python 正则捕获

import re
s = "ip='230.192.168.78'  version='1.0.0'"
res=re.search(r"ip='(?P<ip>d+.d+.d+.d+)'s+(?P<aa>w+)", s)
print dir(res)
print res.group('ip')
print res.group('aa')

C:Python27python.exe C:/Users/TLCB/PycharmProjects/untitled2/socket/t4.py
['__class__', '__copy__', '__deepcopy__', '__delattr__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'end', 'endpos', 'expand', 'group', 'groupdict', 'groups', 'lastgroup', 'lastindex', 'pos', 're', 'regs', 'span', 'start', 'string']
230.192.168.78
version
原文地址:https://www.cnblogs.com/hzcya1995/p/13348300.html