Python正则表达式从字符串中删除电子邮件

dok*_*ndr 4 python regex

需要替换字符串中的电子邮件,因此:

inp = 'abc user@xxx.com 123 any@www foo @ bar 78@ppp @5555 aa@111"
Run Code Online (Sandbox Code Playgroud)

应该导致:

out = 'abc 123 foo bar"
Run Code Online (Sandbox Code Playgroud)

什么正则表达式使用?

In [148]: e = '[^\@]\@[^\@]'
In [149]: pattern = re.compile(e)
In [150]: pattern.sub('', s)  
Out[150]: 'one aom 123 4two'
In [151]: s
Out[151]: 'one ab@com 123 4 @ two'
Run Code Online (Sandbox Code Playgroud)

对我不起作用

Gaw*_*wil 10

替换:
\S*@\S*\s?
通过'' 在这里

演示一些解释::匹配尽可能多的非空格字符:然后是@ :然后是另一个非空格字符序列:最后是一个空格,如果有的话.注意'?' 需要匹配行尾的地址.由于'?'的贪婪,如果有空格,它将始终匹配.


\S*
@
\S*
\s?