Regular Expression to match IP address + wildcard

后端 未结 5 905
旧时难觅i
旧时难觅i 2021-01-02 21:57

I\'m trying to use a RegularexpressionValidator to match an IP address (with possible wildcards) for an IP filtering system.

I\'m using the following Regex:

5条回答
  •  遥遥无期
    2021-01-02 22:10

    [0-9]{1,3} would allow IP addresses of the form 999.999.999.999 . Your IP address range should allow only 0-255.
    Replace all occurences of [0-9]{1,3} with ([0-9]{1,2})|(1[0-9]{2,2})|(2[0-4][0-9])|(25[0-5])
    This does seem very complicated to me, and probably there are better ways of doing this, but it seems correct at first glance.

提交回复
热议问题