"cat Tom 123 and mouse Jerry 456"
,如这个字符串,我们想用通配符找出Tom
和Jerry
import re
text = "cat Tom 123 and mouse Jerry 456"
matches = re.findall("(?:cat |mouse )(.*?)(?: 123| 456)", text)
print(matches) # ['Tom', 'Jerry']
归功于:
(?:...)
是一个非捕获组,不会保存下来
"cat Tom 123 and mouse Jerry 456"
,如这个字符串,我们想用通配符找出Tom
和Jerry
import re
text = "cat Tom 123 and mouse Jerry 456"
matches = re.findall("(?:cat |mouse )(.*?)(?: 123| 456)", text)
print(matches) # ['Tom', 'Jerry']
归功于:
(?:...)
是一个非捕获组,不会保存下来