-
-
Save lt/4162568 to your computer and use it in GitHub Desktop.
Regex to validate (IPv4) CIDR notation (with capture)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Repeating patterns, matches 0-255 in each octet, followed by /0-32 | |
\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 | |
Using subpatterns to achieve the same thing. | |
\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 |
Author
lt
commented
May 16, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment