I need to replace part of a string. I was looking through the Python documentation and found re.sub.
import re
s = '<textarea id="Foo"></textarea>'
output = re.sub(r'<textarea.*>(.*)</textarea>', 'Bar', s)
print output
>>>'Bar'
I was expecting this to print '<textarea id="Foo">Bar</textarea>'
and not 'bar'.
Could anybody tell me what I did wrong?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…