Regular Expressions 101

Community Patterns

IPv4 Address +/- CIDR Slash Notation

0

Regular Expression
Python

r"
^((^|(?<!^)\\.)(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){4}(/(3[0-2]|2[0-9]|1[0-9]|[1-9]))$
"

Description

Grabs an IPv4 address, and if it has a CIDR slash notation, then grab that too.

Submitted by dboyd42 - 2 years ago (Last modified 8 months ago)