python 正则表达式总结
# findall 找出所有的, match 从第一个字符开始找, fullmatch全句完全匹配, search从任意位置开始找
text = "jack最好, jack最好的, jack最好了, jack是最好的" pattern = "jack最好" print(re.findall(pattern, text)) 输出:['jack最好', 'jack最好', 'jack最好'] print(re.match(pattern, text)) 输出:<re.Match object; span=(0, 6), match='jack最好'> print(re.match(pattern, text).group()) 输出:jack最好 print(re.fullmatch(pattern, text)) 输出:None print(re.search(pattern, text)) 输出:<re.Match object; span=(0, 6), match='jack最好'> print(re.search(pattern, text).group()) 输出:jack最好
标签:总结,re,python,text,正则表达式,jack,pattern,print,最好 From: https://www.cnblogs.com/111testing/p/17873933.html