Validating an IP with regex

后端 未结 5 1568
一整个雨季
一整个雨季 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:36

    ^([01]\d{2}|2[0-4]\d|25[0-5]){3}$
    

    Which breaks down in the following parts:

    1. 000-199
    2. 200-249
    3. 250-255

    If you decide you want 4 octets instead of 3, just change the last {3} to {4}. Also, you should be aware of IPv6 too.

提交回复
热议问题