Regex for Matching an IPv4 Address With CIDR Notation
Matches an IPv4 address followed by a slash and a prefix length, like 192.168.1.0/24.
Published October 13, 2026
Matches an IPv4 address followed by a slash and a prefix length, like 192.168.1.0/24.
Key points
- CIDR notation is commonly used to describe network ranges, where the number after the slash indicates the subnet mask length
Example
^(\d{1,3}\.){3}\d{1,3}\/\d{1,2}$