re模塊

https://www.cnblogs.com/python-Specia-Force/p/7784317.html
re過濾Ip地址,稍微高級一點的方法
import re
reg=re.compile(r'(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)')
x = reg.findall('192.168.101.1')
print(x)

reg=re.compile(r'(?:192.168.1)(?:.9)')
x = reg.findall('192.168.1.9')
print(x)
reg=re.compile(r'(192.168.1)(.9)')
x = reg.findall('192.168.1.9')
print(x)


C:\Python36-32\python36.exe D:/py/re_ip.py
['192.168.101.1']
['192.168.1.9']
[('192.168.1', '.9')]

Process finished with exit code 0


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章