您的位置:首页 > 编程语言 > Python开发

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')]

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: