Python regex sub using compile object

Viewed 3626

I have a regex <type '_sre.SRE_Pattern'> and I would like to substitute the matched string with another string. Here is what I have:

compiled = re.compile(r'some regex expression')
s = 'some regex expression plus some other stuff'
compiled.sub('substitute', s)
print(s)

and s should be

'substitute plus some other stuff'

However, my code is not working and the string is not changing.

1 Answers
Related