Using a RegEx to match IP addresses in Python

后端 未结 13 2465
不思量自难忘°
不思量自难忘° 2020-12-01 04:58

I\'m trying to make a test for checking whether a sys.argv input matches the RegEx for an IP address...

As a simple test, I have the following...

imp         


        
13条回答
  •  孤城傲影
    2020-12-01 05:31

    This works for python 2.7:

    import re
    a=raw_input("Enter a valid IP_Address:")
    b=("[0-9]+"+".")+"{3}"
    if re.match(b,a) and b<255:
        print "Valid"
    else:
        print "invalid"
    

提交回复
热议问题