ai didi

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

转载 作者:行者123 更新时间:2023-12-04 22:18:53 24 4
gpt4 key购买 nike

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

inp = 'abc user@xxx.com 123 any@www foo @ bar 78@ppp @5555 aa@111"

应该导致:
out = 'abc 123 foo bar"

要使用什么正则表达式?
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'

对我不起作用

最佳答案

代替 :\S*@\S*\s?经过 ''
演示 here
一些解释:\S* : 匹配尽可能多的非空格字符@ : 然后是@\S* : 然后是另一个非空格字符序列\s? : 最后是一个空间,如果有的话。请注意“?”需要匹配行尾的地址。由于'?'的贪婪,如果有空格,它总是会匹配。

关于Python正则表达式从字符串中删除电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44027943/

24 4 0
文章推荐: kotlin - 为什么在 Kotlin 中运行这个特定的 Cucumber 步骤时会出现 ArrayIndexOutOfBoundsException?
文章推荐: networking - Docker - 创建新网络时如何设置 iface 名称
文章推荐: python-3.x - BadZipFile : File is not a zip by importing keras
文章推荐: jhipster - zsh : command not found: jhipster
行者123
个人简介

我是一名优秀的程序员,十分优秀!

滴滴打车优惠券免费领取
滴滴打车优惠券
全站热门文章
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com