Regular Expressions 101

Community Library Entry

0

Regular Expression
PCRE (PHP <7.3)

/
^(?<srcNet>\d{1,3}\.\d{1,3}\.\d{1,3}|[0-9a-f]{1,4}:[0-9a-f]{1,4}:[0-9a-f]{1,4}:[0-9a-f]{1,4})[.:]
/
gim

Description

This extracts the first three octets of an IPv4 address, or the first half of an IPv6 address. This may be suitable for classifying addresses by address groups.

Submitted by anonymous - 7 years ago