Networkingflags: g
IP Address with CIDR Notation
Match IPv4 addresses with CIDR prefix notation such as 10.0.0.0/8 or 192.168.1.0/24.
Try it in RegexPro →Available in
Pattern
regexengine-agnostic
(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\/(?:3[0-2]|[12]?\d) (flags: g)Raw source: (?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\/(?:3[0-2]|[12]?\d)
How it works
The IPv4 portion uses alternation to strictly validate each octet in the 0–255 range (same as the standalone IPv4 pattern). \/(?:3[0-2]|[12]?\d) appends a / and a CIDR prefix constrained to 0–32.
Examples
Input
10.0.0.0/8Matches
10.0.0.0/8
Input
192.168.1.0/24Matches
192.168.1.0/24
Input
999.0.0.0/33No match
—Common use cases
- •Firewall and security-group rule validation
- •Network configuration file parsing
- •VPC/subnet CIDR input validation
- •IP allowlist/blocklist enforcement
Related patterns
Private IP Address (RFC 1918)
NetworkingMatch IPv4 addresses in the RFC 1918 private ranges: 10/8, 192.168/16, and 172.16/12.
IPv4 Address
NetworkingMatch valid IPv4 addresses with each octet constrained to 0–255.
IPv6 Address
NetworkingMatch full (non-compressed) IPv6 addresses written as eight colon-separated hextets.
MAC Address
NetworkingMatch 48-bit MAC addresses written with colon or hyphen separators (e.g. 00:1A:2B:3C:4D:5E).