正则表达式
发布时间:2020-12-13 22:57:47 所属栏目:百科 来源:网络整理
导读:##########征服python######### 1 使用match对象处理组 import res="life can be dreams life can be great mean person"r=re.compile(r"(?Pfirstw+)a(?Plastw+)")m=r.search(s)print(m.groupdict())print(m.groups())m=r.search(s,9)print(m.groupdict())
##########征服python######### 1 使用match对象处理组 import re s="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') (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |