0
我有一个正则表达式<type '_sre.SRE_Pattern'>
,我想用另一个字符串替换匹配的字符串。以下是我有:使用编译对象的Python正则表达式
compiled = re.compile(r'some regex expression')
s = 'some regex expression plus some other stuff'
compiled.sub('substitute', s)
print(s)
和s
应
'substitute plus some other stuff'
然而,我的代码不能正常使用的串并没有改变。
哦,它的工作。谢谢。 ! –
@ChrisJohnson当然,没问题。 –