那就行了
regex = re.compile(r'\b(liquid marinade)\b', re.IGNORECASE)
print(regex.search(test))
这个
re.IGNORECASE
传递给的参数
search
实际上是起始位置。
被抓了很多次
re.sub
以及(经典问题:
Python re.sub with a flag does not replace all occurrences
,我建议在添加标志时使用
flags
关键字,而不是
位置传球
因为在
re
方法(开始位置、计数、命名):
flags=re.IGNORECASE
如果它起作用(比如
再保险公司
或
re.compile
,然后,好的,如果不支持它,您将得到(如这里所示):
regex.search(test,flags=re.IGNORECASE) # wrong but explicit!
TypeError: 'flags' is an invalid keyword argument for this function
至少它不做其他的事…