Regular Expressions 101

Community Patterns

Extract /24 (IPv4) or /64 (IPv6)

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 - 6 years ago