1. 程式人生 > >python五十六課——正則表達式(常用函數之findall)

python五十六課——正則表達式(常用函數之findall)

如果 sina com 常用 div mpi .com earch string


4).函數:findall(regex,string,[flags=0]):

參數:

和match、search一樣理解

功能:

將所有匹配成功的子數據(子串),以列表的形式返回;

如果一個都沒有匹配成功,那麽返回一個空列表

compile()配合search()使用:
pat=re.compile(rwww)
matchobj=pat.search(www.sina.com!!www.baidu.com.com!!www)
print(matchobj)

函數:findall(regex,string,[flags=0]):
參數:
和match、search一樣理解

功能:
將所有匹配成功的子數據(子串),以列表的形式返回;
如果一個都沒有匹配成功,那麽返回一個空列表
lt=re.findall(rWWW,www.sina.com!!www.baidu.com!!www)
lt=re.findall(rWWW,www.sina.com!!www.baidu.com!!www,flags=re.I)
print(lt,type(lt))

compile()配合findall()使用:
pat=re.compile(rwww,flags=re.I)
lt=pat.findall(www.sina.com!!www.baidu.com!!www)
print(lt)

python五十六課——正則表達式(常用函數之findall)