re.findall(r'[\w]+@+[\w.]','blahh [email protected] yipee']


返回['ggg@g']

为什么不返回['[email protected]']或至少返回['ggg@google']

最佳答案

\w+@+[\w.]+

         ^^


您未能添加一个量词,因此@之后只能得到一个字符。

它应该是

`re.findall(r'[\w]+@+[\w.]+','blahh [email protected] yipee')`


另外,如果只能有一个@,则可以删除其前面的量词以使其成为\w+@[\w.]+

输出:['[email protected]']

See Demo

Quantifier: + Between one and unlimited times, as many times as possible, giving back as needed [greedy]

Quantifier: * Between zero and unlimited times, as many times as possible, giving back as needed [greedy]

关于python - python中的正则表达式:findall,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28757748/

10-10 13:41