根据我在这个问题上收到的答案,我编辑了以下正则表达式。
我的字符串混合了年和月的术语。我需要用正则表达式检测两者。
String1 = " I have total exp of 10-11 years. This includes 15yearsin SAS and 5
years in python. I also have 8 months of exp in R programming."
import re
pat= re.compile(r'\d{1,3}(?:\W+\d{1,3})?\W+(?:plus\s*)?(?:year|month|Year|Month)s?\b', re.X)
experience = re.findall(pat,String1 )
print(experience)
['10-11 years', '5 years', '8 months']
但我也想要没有空格的条款,即 15 年(因为我正在阅读自由流动的文本)。
任何人都可以帮助实现正确的正则表达式吗?
森林海
相关分类