我有一个小的python程序,我希望单词“已验证”(无论是用大写,小写还是大写和小写混合编写)。要重置为“已验证”。我如何重写下面的代码?
import re
text="verified, vERIFIED, VERIFIED"
text=re.sub(r'\verified', 'Verified', text, flags=re.IGNORECASE)
print text
Expected output: Verified, Verified, Verified
Actual output:verified, vERIFIED, VERIFIED
答案 0 :(得分:2)
只需在v
import re
text="verified, vERIFIED, VERIFIED"
text=re.sub(r'verified', 'Verified', text, flags=re.IGNORECASE)
print text