Regular Expressions 101

Community Patterns

Community Library Entry

0

Regular Expression
ECMAScript (JavaScript)

/
(^([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}$|^([0-9a-fA-F]{1,4}:){6}:(?:[0-9a-fA-F]{1,4}){0,1}$|^([0-9a-fA-F]{1,4}:){5}(?:(:[0-9a-fA-F]{1,4}){1,2}|:)$|^([0-9a-fA-F]{1,4}:){4}(?:(:[0-9a-fA-F]{1,4}){1,3}|:)$|^([0-9a-fA-F]{1,4}:){3}(?:(:[0-9a-fA-F]{1,4}){1,4}|:)$|^([0-9a-fA-F]{1,4}:){2}(?:(:[0-9a-fA-F]{1,4}){1,5}|:)$|^[0-9a-fA-F]{1,4}:(?:(:[0-9a-fA-F]{1,4}){1,6}|:)$|^:((:[0-9a-fA-F]{1,4}){1,7}|:)$)|(^(?:(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9])$)
/
ig

Description

This regexp match an ip address in v6 or v4 form. Included V6 compact form (:: in place of :0000:). Doesn't matches addresses range or mixed format (like y:y:y:y:y:y:x.x.x.x)

Submitted by Emanuele Benedetti - 2 years ago (Last modified 2 years ago)