Python RE模块中search()和match()的区别
2015-09-01 21:38
761 查看
# -*- coding: utf-8 -*- import re s1 = "helloworld, qwer" s2 = "hello world, qwer" w1 = 'hello' w2 = 'world' m1 = re.search(w1, s1) # 扫描整个字符串查找匹配 m2 = re.match(w1, s2) # 只在字符串的开始位置匹配 m3 = re.search(w2, s1) m4 = re.match(w2, s2) if m1: print 'm1: ', m1.group() if m2: print 'm2: ', m2.group() if m3: print 'm3: ', m3.group() if m4: print 'm4: ', m4.group()
输出:
m1: hello
m2: hello
m3: world
原文:http://blog.csdn.net/cnmilan/article/details/9071999
相关文章推荐
- 2015/9/1 Python基础(6):列表
- 轻松python之文件专题-搜索文本并写入文件专题
- 轻松python之文件专题-搜索文本并写入文件专题
- python 爬虫
- windows 系统下 python 集成环境搭建(pycharm)
- 轻松python专题--文件
- 轻松python专题--文件
- 轻松python之文件专题-读取文件专题
- 轻松python之文件专题-读取文件专题
- Python 学习笔记-面向对象编程
- python虚拟机virturalenv的使用
- python学习(1)--python处理文本
- Python 之 将 list 存储为 .mat 文件
- python unittest源码解析一----测试用例是如何被执行的
- python实现杨辉三角(使用生成器generator)
- python+Eclipse+pydev环境搭建(转)
- Python - Headless Selenium WebDriver Tests using PyVirtualDisplay
- Python 随手记
- 基础知识(七)opencv、python、人脸框检测
- python 遇到的异常