temp = r"this is string1, that is string2"
re_keys = re.compile(r"string1|string2|th|str")
res = re_keys.findall(temp)
print(res)
输出结果为:['th', 'string1', 'th', 'string2']
为什么没有关键词“str"的结果啊
temp = r"this is string1, that is string2"
re_keys = re.compile(r"string1|string2|th|str")
res = re_keys.findall(temp)
print(res)
输出结果为:['th', 'string1', 'th', 'string2']
为什么没有关键词“str"的结果啊
re.compile(r"string1|string2|th|str")
优先级是左到右的,你配对string1、string2就不会匹配str了