Skip to main content
Regexflux

IPv4 CIDR Notation

intermediate

Matches IPv4 addresses with CIDR subnet prefix like 192.168.1.0/24.

ipcidrsubnetnetwork

Pattern

/(?:(?: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)/g

Try It

0 of 6 strings matched

Explanation

Matches an IPv4 address (four octets 0-255) followed by a slash and a CIDR prefix length (0-32).

Test Strings

Matching

  • 192.168.1.0/24
  • 10.0.0.0/8
  • 172.16.0.0/12

Non-matching

  • 192.168.1.0
  • not-a-cidr
  • 10.0.0/8

Language Compatibility

LanguageSupport
JSFull support
PYTHONFull support
JAVAFull support
PHPFull support
GOFull support

Code Snippets

const regex = /(?:(?: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)/g;
const text = "your text here";
const matches = text.match(regex);
console.log(matches);

Related Patterns