Validating an IP with regex

后端 未结 5 1570
一整个雨季
一整个雨季 2021-01-14 01:14

I need to validate an IP range that is in format 000000000 to 255255255 without any delimiters between the 3 groups of numbers. Each of the three groups that the final IP c

5条回答
  •  太阳男子
    2021-01-14 01:43

    for match exclusively a valid IP adress use

    (25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}
    

    instead of

    ([01]?[0-9][0-9]?|2[0-4][0-9]|25[0-5])(([01]?[0-9][0-9]?|2[0-4][0-9]|25[0-5])){3}
    

    because many regex engine match the first possibility in the OR sequence

    you can try your regex engine with : 10.48.0.200

提交回复
热议问题