如何在不使用 re.compile 的情况下编写不区分大小写的 Python 正则表达式?
pythonserver side programmingprogramming更新于 2025/7/2 12:28:17
我们可以将 re.IGNORECASE 传递给 search、match 或 sub 的 flags 参数 −
示例
import re
print (re.search('bush', 'BuSh', re.IGNORECASE))
print (re.match('bush', 'BuSh', re.IGNORECASE))
print (re.sub('bush', 'xxxx', 'Bushmeat', flags=re.IGNORECASE))
输出
<_sre.SRE_Match object at 0x0000000005316648> <_sre.SRE_Match object at 0x0000000005316648> xxxxmeat
相关文章
有用资源
python 参考教程 - 该教程包含有关 python 的更多信息:https://www.cainiaomax.com/python/

