Regular Expressions 101

Community Patterns

IPv4, IPv6 and CIDR ranges validation pattern

1

Regular Expression
ECMAScript (JavaScript)

/
^(?:(?:[0-9]{1,3}\.){3}[0-9]{1,3}(?:\/(?:[0-9]|[12][0-9]|3[0-2]))?|(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}(?:\/(?:[0-9]|[1-9][0-9]|1[0-1][0-9]|12[0-8]))?)$
/
mg

Description

This regex can be used to validate IPv4 and IPv6 addresses as well as CIDR ranges

Submitted by Simon - 2 months ago