我有这个字符串:
maria 10 years maria 10 maria10 maria10 years
当下一个字不是maria
时,我希望匹配10
后跟years
。我试过这样:
\maria\s?[0-9]+(?!years)
但即使下一个字是maria 10
year
答案 0 :(得分:2)
您刚忘记years
之前的空格:
In [1]: import re
In [2]: s = "maria 10 years maria 10 maria10 maria10 years"
In [3]: re.findall(r"(\maria\s?[0-9]+)\s(?!years)", s)
Out[3]: ['maria 10', 'maria10']
答案 1 :(得分:0)