Findall函數(shù)的使用
如何用正則表達式查找字符串中的所有email,并輸出
- 依然使用re模塊
- 使用findall函數(shù)
- 前置條件可以加上09-诀艰,大寫柬甥,小寫字母的組合
- 查找含有com,net的郵箱地址
import re
s = 'my email address is abc@163.com, your email address is showlove@sina.com,he email is flower@yahoo.cn'
prefix = '[0-9a-z-A-Z]+@[0-9a-z-A-Z]+\.'
m = re.findall(prefix+'com|' + prefix + 'net',s,re.I)
print(m)
hexianling.png
總結(jié)
findall函數(shù)用于搜索字符串中的所有滿足條件的子字符串饮六,該函數(shù)第一個參數(shù)是用于指定正則表達式,第2個參數(shù)是用于指定待匹配的字符串苛蒲,第3個參數(shù)是用于指定選項卤橄,如re.I表示忽略大小寫