Skip to content

Instantly share code, notes, and snippets.

@nikic
Created November 28, 2012 16:55
Show Gist options
  • Save nikic/4162505 to your computer and use it in GitHub Desktop.
Save nikic/4162505 to your computer and use it in GitHub Desktop.
Regex to validate (IPv4) CIDR notation (with capture)
\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/(3[0-2]|[1-2]?[0-9])\b
\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.((?1))\.((?1))\.((?1))/(3[0-2]|[1-2]?[0-9])\b
@gangadhars
Copy link

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment