我有以下字符串:
'iamgood@yahoo.com, cc.a@est.gov.cn, j_193@ywuancjds.com, super.hard.bb@ililsa.bi'
我要提取com, gov, com, bi
。
我写了(?<=@)\w+
正则表达式,但事实证明它提取了yahoo,est,ywuancjds,ililsa
。
我不知道如何在@
后面加上词汇。
答案 0 :(得分:2)
您可以使用
re.findall(r'@[^\s.]+\.(\w+)', text)
详细信息
@
-一个@
字符[^\s.]+
-除空格和点之外的1个或多个字符\.
-一个点(\w+)
-第1组(此组中捕获的值仅由re.findall
返回):一个或多个单词字符。Python演示代码段:
import re
text = "iamgood@yahoo.com, cc.a@est.gov.cn, j_193@ywuancjds.com, super.hard.bb@ililsa.bi"
print( re.findall(r"@[^\s.]+\.(\w+)", text) )
# => ['com', 'gov', 'com', 'bi']