正则表达式匹配所有现有的可能性

时间:2021-03-15 15:34:20

标签: python regex

我有一个这样的正则表达式:

(?:(?:(?:1[0-2]|0?[1-9])) *[ /.-] *(?:3[01]|[12][0-9]|0?[1-9]) *[ /.-] *(?:19\d{2}|20\d{2}|1[6-9]|2[0-9]))

我想将它与此文本匹配:

001-001 09/23/2019 heure :42

我匹配的是:

01 09/23

我想要什么作为比赛:

01 09/23 AND 09/23/2019

我的代码实际上是:

regex = re.compile(pattern)
matches = regex.findall(text)

有什么我应该打开的选项吗? 谢谢

1 个答案:

答案 0 :(得分:-1)

正如@第四只鸟建议我看overlapping matches,它与:

import regex as re
matches = re.findall(pattern, text, overlapped=True)
相关问题