Regular expression - how to match IP address in python
阿神
阿神 2017-06-28 09:23:37
0
1
924

Now I need to match all the IP addresses in the list that are not x.x.x.1. I don’t know how to do this. What I think of is to use regular matching. I don’t know much about regular matching. Can anyone help me?

阿神
阿神

闭关修行中......

reply all(1)
小葫芦

Rudimentary version~, it does not match the legality of ip, it only matches x.x.x.1

import re
ip_list = [
    '1.2.2.1',
    '1.2.3.3',
    '16.25.22.1',
    '112.23.22.1',
    '11.2.2.1',
    '1.2.32.11',
]
ip_regx = re.compile(r'(?:[\d]+\.)+1$')
for _ in ip_list:
    if re.search(ip_regx, _):
        print _
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template