Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Is there a way to add some text after pattern in python string?
For example I can do it easily with sed:
sed
sed 's/my [a-z]\+ pattern/& lost_text/'
where & means the whole matched pattern.
&
search and man pages didn't help me :(
您正在寻找re.sub:
re.sub
例子:
>>> import re >>> re.sub(r'(\d+)',r'\1--','abcd1cf123vf') 'abcd1--cf123--vf'