2.6 字符串忽略大小写的搜索替换
问题
解决方案
>>> re.findall('python', text, flags=re.IGNORECASE)def matchcase(word):
def replace(m):
text = m.group()
if text.isupper():
return word.upper()
elif text.islower():
return word.lower()
elif text[0].isupper():
return word.capitalize()
else:
return word
return replace讨论
Last updated