Regular Expressions 101

Community Patterns

IPv4 non zero first and last octet

0

Regular Expression
PCRE2 (PHP >=7.3)

/
^(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|0?[1-9][0-9]?|0?[0-9]?[1-9])(.(25[0-5]|2[0-4][0-9]|[0-1]?[0-9]?[0-9])){2}.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|0?[1-9][0-9]?|0?[0-9]?[1-9])$
/
gm

Description

When validating an IPv4 address I often have to reject devices that the first and last octet are 0.

Submitted by John Cutburth - 2 years ago