36 - 用正则表达式查找字符串中所有的email

用正则表达式查找字符串中所有的email,并输出这些email。

  • 要求:
    • 所有的email域名必须是.com 或.net 的
    • 不区分大小写
# findall函数的用法
# 用于搜索字符串中所有满足条件的子字符串
# 第一个参数: 用于指定正则表达式
# 第二个参数: 用于指定待匹配的字符串
# 第三个参数: 用于指定选项,如re.I表示忽略大小写

import re

s = '我的Email是[email protected], 你的email是[email protected]吗, 还是[email protected]'

prefix = '[0-9a-zA-Z]+@[0-9a-zA-Z]+\.'
result = re.findall(prefix + 'com|' + prefix + 'net', s, re.I)
print(result)
['[email protected]', '[email protected]']

持续更新中。。。。

发布了133 篇原创文章 · 获赞 137 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/qq_29339467/article/details/104464624
36
今日推荐