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:\Python27\python.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&
python 正则捕获
最新推荐文章于 2024-08-25 14:05:43 发布
本文详细探讨了Python中使用正则表达式进行数据捕获的方法,包括分组、非捕获组以及命名组的应用。通过实例解析,帮助读者掌握如何有效地从文本中提取所需信息。
摘要由CSDN通过智能技术生成