Regular Expressions 101

Community Patterns

IPv4 + IPv6 w/ Zero Compression

1

Regular Expression
PCRE2 (PHP >=7.3)

/
(?:\d{1,3}\.){3}\d{1,3}\b|\b(?:[A-Fa-f0-9]{1,4}:){7}[A-Fa-f0-9]{1,4}\b|\b(?:[A-Fa-f0-9]{1,4}:){0,6}(?:[A-Fa-f0-9]{1,4})?::(?:[A-Fa-f0-9]{1,4}:){0,5}(?:[A-Fa-f0-9]{1,4})?
/
gm

Description

Regex pattern detection for IPv4 addresses and IPv6 addresses in zero compression format.

Submitted by Lewis Wigmore - 3 months ago (Last modified 3 months ago)