我想利用匹配大小写选项。我有一段代码来搜索列表中的字符串。我想有一种更好的方法来做同样的事情。python正则表达式匹配案例选项
searchString = "maki"
itemList = ["Maki", "moki", "maki", "Muki", "Moki"]
resultList = []
matchCase = 0
for item in itemList:
if matchCase:
if re.findall(searchString, item):
resultList.append(item)
else:
if re.findall(searchString, item, re.IGNORECASE):
resultList.append(item)
我可以用re.findall(searchString, item, flags = 2)
因为re.IGNORECASE
基本上是一个整数(2),但我不知道哪个数字将意味着“matchcase”选项。
''返回小写列表,你并不真的需要一个正则表达式这个问题。 – Maroun