import re s = '18year old 23 year old 99 years old but not 25-year-old and 91year old cousin is 99 now and 90-year-old or 102 year old'
从中s
,我想使用正则表达式提取所有 90 岁或以上的年龄。例如,99 years old
将被提取但不是18year old
.
我试过以下
reg = r'(9\d|\d{3,})(-year-old)|(9\d|\d{3,})( year old)' r1 = re.findall(reg,s) r1
这给了我
[('90', '-year-old', '', ''), ('', '', '102', ' year old')]
理想情况下,我想要这个输出
['99 years old', '91year old', '90-year-old', '102 year old' ]
如何更改我的正则表达式reg
以获得我想要的输出?
皈依舞
相关分类