Python里面search()和match()的区别
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)
例如:
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里面search()和match()的区别】相关文章
1. Python里面search()和match()的区别
7. 软件测试LoadRunner面试题:What is think time? How do you change the threshold?
8. C++:memset ,memcpy和strcpy的根本区别
9. JSP和EJB可以共享HttpSession么?EJB里面可以改变session里面的内容
10. 请写出一段Python代码实现删除一个list里面的重复元素
本文来源:https://www.mianshiwenti.com/a13493.html
进入下载页面
上一篇:Python中如何定义一个函数
下一篇:介绍一下except的用法和作用
﹝Python里面search()和match()的区别﹞相关内容
- 介绍一下Python中webbrowser的用法
- 用Python匹配HTML tag的时候,<.*>和<.*?>有什么区别
- const char*, char const*, char*const的区别是什么
- JAVA语言如何进行异常处理,关键字:throws,throw,try,catch,finally分别代表什么意义?在try块中可以抛出异常吗?
- Oracle里面User和Schema的区别是什么
- Python中如何定义一个函数
- 华为python面试题
- 如何用Python来进行查询和替换一个文本字符串
- Python的两道面试题
- Python是如何进行类型转换的