2

Is there a way to add some text after pattern in python string?

For example I can do it easily with sed:

sed 's/my [a-z]\+ pattern/& lost_text/'

where & means the whole matched pattern.

search and man pages didn't help me :(

4

1 回答 1

3

您正在寻找re.sub

例子:

>>> import re
>>> re.sub(r'(\d+)',r'\1--','abcd1cf123vf')
'abcd1--cf123--vf'
于 2013-07-08T18:37:38.907 回答