Advertisement

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

Test it: match & no-match examples

Every row is loaded straight into the tester — click Try to see the match live:

InputResultWhy
192.168.1.0/24Matchstandard /24Try →
10.0.0.0/8Match/8 networkTry →
192.168.1.1/32Matchhost routeTry →
192.168.1.0/33No matchprefix 33 invalidTry →
192.168.1.0No matchmissing /prefixTry →

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.
Open the regex tester →

FAQ

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.