You can directly find a regular match for IP on the Internet, but the one on the Internet may not be correct, and it is not easy to verify, so we will write one ourselves.
There is a tool for generating regular expressions from a numerical range. [Tools can be found online] ip rules 0-255.0-255.0-255.0-255/0-32
Given in "Must Know Regular Expressions". It’s easy to make mistakes when you write it yourself
^((0|1[0-9]{0,2}|2[0-9]{0,1}|20-4|25[0-5]|3-9{0,1}).){3}(0|1[0-9]{0,2}|2[0-9]{0,1}|20-4|25[0-5]|3-9{0,1})(?(/)/([0-9]|1-2|3[0-2])|)$
new RegExp(/([0-9]{1,3}.{1}){3}[0-9]{1,3}/)
You can directly find a regular match for IP on the Internet, but the one on the Internet may not be correct, and it is not easy to verify, so we will write one ourselves.
There is a tool for generating regular expressions from a numerical range. [Tools can be found online]
ip rules
0-255.0-255.0-255.0-255/0-32
0-255
([0-9]|[1-8][0-9]|9[0-9]|1[0-9]{2}|2[0-4][0-9]|25 [0-5])
0-255.
([0-9]|[1-8][0-9]|9[0-9]|1[0-9]{2}|2[0-4][0-9]|25 [0-5]).
Repeat 3 times
(([0-9]|[1-8][0-9]|9[0-9]|1[0-9]{2}|2[0-4][0-9]| 25[0-5]).){3}
Splice again 0-255
(([0-9]|[1-8][0-9]|9[0-9]|1[0-9]{2}|2[0-4][0-9]| 25[0-5]).){3}([0-9]|[1-8][0-9]|9[0-9]|1[0-9]{2}|2[0 -4][0-9]|25[0-5])
0-32
([0-9]|[12][0-9]|3[0-2])
All stitched together
(([0-9]|[1-8][0-9]|9[0-9]|1[0-9]{2}|2[0-4][0-9]| 25[0-5]).){3}([0-9]|[1-8][0-9]|9[0-9]|1[0-9]{2}|2[0 -4][0-9]|25[0-5])/([0-9]|[12][0-9]|3[0-2])
Add first separator
^(([0-9]|[1-8][0-9]|9[0-9]|1[0-9]{2}|2[0-4][0-9] |25[0-5]).){3}([0-9]|[1-8][0-9]|9[0-9]|1[0-9]{2}|2[ 0-4][0-9]|25[0-5])/([0-9]|[12][0-9]|3[0-2])$
or
(?^ |s)(([0-9]|[1-8][0-9]|9[0-9]|1[0-9]{2}|2[0-4][0-9] |25[0-5]).){3}([0-9]|[1-8][0-9]|9[0-9]|1[0-9]{2}|2[ 0-4][0-9]|25[0-5])/([0-9]|[12][0-9]|3[0-2])(?:s|$)
The dividing symbols are replaced according to the actual situation
If no separator is added,
33.33.33.1/24
will be matched into33.33.33.1/2
or99933.33.33.1/24
will also be matched