此正则表达式:
import re
string = 'I am a long string with many regexes matching'
pattern = '.*(?:with|regexes)'
print(re.findall(pattern, string))
返回
['I am a long string with many regexes']
我该如何使其返回:
['I am a long string with']
即当同时存在正则表达式的短版本和长版本时,返回较短的字符串。