Regular Expressions 101

Community Patterns

1...45678...902

Community Library Entry

0

Regular Expression
PCRE2 (PHP >=7.3)

/
^(?:::|([[:xdigit:]]{1,4})(?::(?1)){7}|(?:(?1):){1,6}:|(?:(?1):){5}:(?1)|(?:(?1):){4}(?::(?1)){1,2}|(?:(?1):){3}(?::(?1)){1,3}|(?:(?1):){2}(?::(?1)){1,4}|(?1):(?::(?1)){1,5}|:(?::(?1)){1,6})$
/
gmi

Description

Matches an IPv6 address.

Performances are the same as the excellent one from frusty. This regular expression uses pattern repetition (?n) to reduce the length to 191 characters.

Submitted by Piwi - 2 years ago