Regular Expressions 101

IPv4 no leading zeros

Open Workspace
  • JavaScript
  • Match
1

Regular Expression

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

Description

An IPv4 expression that doesn't allow leading zeros in octets. 10.0.0.1 will pass 10.0.0.01 shouldn't pass

Submitted by machfist