Regular Expressions 101

Community Patterns

Community Library Entry

0

Regular Expression
PCRE2 (PHP >=7.3)

/
\b(?:(?<FirstOctet>(?:25[0-5]|2[0-4][0-9]|[0-1][0-9]{2})|(?:[0-9]{1,2}))\.(?<SecondOctet>(?:25[0-5]|2[0-4][0-9]|[0-1][0-9]{2})|(?:[0-9]{1,2}))\.(?<ThirdOctet>(?:25[0-5]|2[0-4][0-9]|[0-1][0-9]{2})|(?:[0-9]{1,2}))\.(?<FourthOctet>(?:25[0-5]|2[0-4][0-9]|[0-1][0-9]{2})|(?:[0-9]{1,2}))){1}\b
/
gm

Description

Matches on IPv4 addresses and groups each octet.

Submitted by Jon Stinnett - 2 years ago