0
我正在执行此操作。RegEx - 或运营商
print(re.findall(r'(<OR|<PP).*>', '<OR first><PP second><OR third>'))
预计:
['<OR first>', '<PP second>', '<OR third>']
实际:
['<OR']
任何身体不知道怎样才能达到预期?
我正在执行此操作。RegEx - 或运营商
print(re.findall(r'(<OR|<PP).*>', '<OR first><PP second><OR third>'))
预计:
['<OR first>', '<PP second>', '<OR third>']
实际:
['<OR']
任何身体不知道怎样才能达到预期?
import re
print(re.findall(r'(?:<OR|<PP)[^>]*>', '<OR first><PP second><OR third>'))
注意
.*
比赛贪婪,所以你的模式整个字符串
谢谢匹配塞巴斯蒂安Proske! –
而不是'[^>] *'你也可以使用'。*?',这是非贪婪的等价于'。*' – qzb