Python RE模块中search()和match()的区别
2014-12-17 10:35
330 查看
本文转载自http://blog.csdn.net/cnmilan/article/details/9071999
match()函数只检测RE是不是在string的开始位置匹配,
search()会扫描整个string查找匹配;
也就是说match()只有在0位置匹配成功的话才有返回,
如果不是开始位置匹配成功的话,match()就返回none。
例如:
print(re.match(‘super’, ‘superstition’).span()) 会返回(0, 5)
而print(re.match(‘super’, ‘insuperable’)) 则返回None
search()会扫描整个字符串并返回第一个成功的匹配
例如:print(re.search(‘super’, ‘superstition’).span())返回(0, 5)
print(re.search(‘super’, ‘insuperable’).span())返回(2, 7)
match()函数只检测RE是不是在string的开始位置匹配,
search()会扫描整个string查找匹配;
也就是说match()只有在0位置匹配成功的话才有返回,
如果不是开始位置匹配成功的话,match()就返回none。
例如:
print(re.match(‘super’, ‘superstition’).span()) 会返回(0, 5)
而print(re.match(‘super’, ‘insuperable’)) 则返回None
search()会扫描整个字符串并返回第一个成功的匹配
例如:print(re.search(‘super’, ‘superstition’).span())返回(0, 5)
print(re.search(‘super’, ‘insuperable’).span())返回(2, 7)
相关文章推荐
- Python RE模块中search()和match()的区别
- python正则表达式模块re中search和match方法的区别
- 3分钟内理解Python的re模块中match、search、findall、finditer的区别
- Python RE模块中search()和match()的区别
- Python RE模块中search()和match()的区别
- python re模块search()与match()区别
- Python中re的match、search、findall、finditer区别
- Python中re的match、search、findall、finditer区别
- python 正则表达式精华 re.match与re.search的区别
- python re模块的match(),search()
- python 正则表达式注意事项和re.match()和re.search()区别
- python re 里面match 和search的区别
- python re 里面match 和search的区别
- Python中re的match、search、findall、finditer区别
- Python中正则表达式match()、search()函数及match()和search()的区别详解
- 正则表达式之re.search()与re.match()用法区别
- python正则表达式match和search的区别
- Python中的re.search和re.findall之间的区别2
- python re.search模块实验
- Python3的re.match()、re.search()和re.findall()