Regular Expressions 101

Community Patterns

Community Library Entry

2

Regular Expression
PCRE2 (PHP >=7.3)

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

Description

POSIX ERE compatible, suitable for usage in Bash [[ testing

Attributions

Derived from regex101: RFC1918 - Private IPv4 addresses by 0100101101001.

Submitted by anonymous - a year ago