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當然,沒問題。 –