IPv4 Address and CIDR Network Notation Detection REGEX

IPv4 Address and CIDR network detection

Addresses - 0.0.0.0 thru 9.255.255.255 with CIDR mask from /0 to /32 - the CIDR portion is optional

\b[0-9](\.([0-9]|[0-9]{2}|[01][0-9]{1,2}|2[0-4][0-9]|25[0-5])){3}(/([0-9]|[12][0-9]|3[0-2])){0,1}\b

Addresses - 10.0.0.0 thru 19.255.255.255 and 100.0.0.0 thru 199.255.255.255 with CIDR mask from /0 to /32 - the CIDR portion is optional

\b[01][0-9]{1,2}(\.([0-9]|[0-9]{2}|[01][0-9]{1,2}|2[0-4][0-9]|25[0-5])){3}(/([0-9]|[12][0-9]|3[0-2])){0,1}\b

Addresses - 20.0.0.0 thru 99.255.255.255 with CIDR mask from /0 to /32 - the CIDR portion is optional

\b[2-9][0-9](\.([0-9]|[0-9]{2}|[01][0-9]{1,2}|2[0-4][0-9]|25[0-5])){3}(/([0-9]|[12][0-9]|3[0-2])){0,1}\b

Addresses - 200.0.0.0 thru 249.255.255.255 with CIDR mask from /0 to /32 - the CIDR portion is optional

\b2[0-4][0-9](\.([0-9]|[0-9]{2}|[01][0-9]{1,2}|2[0-4][0-9]|25[0-5])){3}(/([0-9]|[12][0-9]|3[0-2])){0,1}\b

Addresses - 250.0.0.0 thru 255.255.255.255 with CIDR mask from /0 to /32 - the CIDR portion is optional

\b25[0-5](\.([0-9]|[0-9]{2}|[01][0-9]{1,2}|2[0-4][0-9]|25[0-5])){3}(/([0-9]|[12][0-9]|3[0-2])){0,1}\b


Copyright 2007-2021 ZSCALER, INC.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.