python 正则表达式
2015-08-08 16:24
579 查看
import re
pattern=re.compile(fmt)
m=pattern.match(str)
或
m=re.match(fmt,str)
返回
m.group() 所有匹配
m.groups() 等价于[group(1),group(2),...],返回括号括起的分组
>>> match = re.search(r'(\w+), (\w+): (\S+)', contactInfo)
>>> match.group(1)
'Doe'
>>> match.group(2)
'John'
>>> match.group(3)
'555-1212'
>>> match.group(0)
'Doe, John: 555-1212'
>>> match.start()
0
>>> match.end()
3
>>> re.findall(r'(\w+), (\w+): (\S+)', contactInfo)
[('Doe', 'John', '555-1212')]
pattern=re.compile(fmt)
m=pattern.match(str)
或
m=re.match(fmt,str)
返回
m.group() 所有匹配
m.groups() 等价于[group(1),group(2),...],返回括号括起的分组
>>> match = re.search(r'(\w+), (\w+): (\S+)', contactInfo)
>>> match.group(1)
'Doe'
>>> match.group(2)
'John'
>>> match.group(3)
'555-1212'
>>> match.group(0)
'Doe, John: 555-1212'
>>> match.start()
0
>>> match.end()
3
>>> re.findall(r'(\w+), (\w+): (\S+)', contactInfo)
[('Doe', 'John', '555-1212')]
相关文章推荐
- 自学perl 系列1
- 理解Python中的With语句
- Python快速实现文件共享
- Python基础教程笔记——第7章:更加抽象(类)
- ubuntu下Python虚拟环境的安装、激活、退出
- python datatime
- python_random随机
- win10如何安装python?win10安装python图文教程
- python实现下载指定网址所有图片的方法
- 使用python操作MySQL
- Python安装.whl包的一系列问题
- Python环境下安装PyOpenGL
- python正则表达式 re (一)
- Python实现多线程抓取妹子图
- Python基础教程笔记——第6章:抽象(函数)
- python通过BeautifulSoup分页网页中的超级链接
- 1.Python的subprocess模块
- Python字符串操作集锦之ASCII码与字符互换
- Python字符串操作集锦之字符串编码解码函数
- Python字符串操作集锦之字符串映射表