Using a RegEx to match IP addresses in Python

后端 未结 13 2468
不思量自难忘°
不思量自难忘° 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:26

    regex for ip v4:

    ^((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]?)$
    

    otherwise you take not valid ip address like 999.999.999.999, 256.0.0.0 etc

提交回复
热议问题