正则表达式

来源:互联网 发布:mac 因为找不到原身 编辑:程序博客网 时间:2024/06/03 21:53

##########征服python#########

1 使用match对象处理组

import res="life can be dreams life can be great mean person"r=re.compile(r"(?P<first>\w+)a(?P<last>\w+)")m=r.search(s)print(m.groupdict())print(m.groups())m=r.search(s,9)print(m.groupdict())print(m.groups())
 结果
{'last': 'n', 'first': 'c'}('c', 'n'){'last': 'ms', 'first': 'dre'}('dre', 'ms')

0 0
原创粉丝点击