Pattern library / Network & URLs
Regex to Match IPv4 CIDR Notation
Validates IP/prefix where the prefix is 0-32. Useful for firewall rules, GA4 IP filters, and network config validation.
The pattern
^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/(3[0-2]|[12]?[0-9])$
Load this pattern into the tester →
How the pattern works
[0-9]{1,3}— octet (shape only; validate 0-255 in code)./(3[0-2]|[12]?[0-9])— prefix 0-32.- Regex validates shape; verify octet ranges in code.
Test it: match & no-match examples
Every row is loaded straight into the tester — click Try to see the match live:
| Input | Result | Why | |
|---|---|---|---|
192.168.1.0/24 | Match | standard /24 | Try → |
10.0.0.0/8 | Match | /8 network | Try → |
192.168.1.1/32 | Match | host route | Try → |
192.168.1.0/33 | No match | prefix 33 invalid | Try → |
192.168.1.0 | No match | missing /prefix | Try → |
Where to use it
JavaScript
const re = /^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\/(3[0-2]|[12]?[0-9])$/;
re.test('192.168.1.0/24'); // true
Python
import re
re.match(r'^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/(3[0-2]|[12]?[0-9])$', '192.168.1.0/24')
Common mistakes
Test this pattern on your own data
Paste it into the free tester with your real strings — nothing leaves your browser.
FAQ
Related patterns
For GA4-specific patterns, see the GA4 regex cheat sheet, the page path regex guide, the event filter regex guide, the GA4 regex match types, the custom channel grouping guide and RE2 vs PCRE. Browse the full regex pattern library.