Regular Expressions 101

Community Patterns

Community Library Entry

2

Regular Expression
PCRE2 (PHP >=7.3)

/
^(10(\.(1?\d\d?|2([0-4]\d?|5[0-5])))(?2)|172\.(1[6-9]|2\d|3[0-2])(?2)|192\.168(?2))(?2)$
/
gm

Description

Validate a given IP v4 address against all three defined Private IPv4 Subnets as statet in RFC1918

  • 10.0.0.0/8
  • 172.16.0.0/20
  • 192.168.0.0/16

Wikipedia Link RFC Link

Submitted by 0100101101001 - 3 years ago