Regex tester / pattern library

Regex: ipv4 address

/^((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)$/ Test it live

How it works

Four octets, each constrained to the real 0–255 range: 25[0-5] covers 250–255, 2[0-4]\d covers 200–249, 1\d\d covers 100–199, [1-9]?\d handles 0–99 without leading zeros.

Honest caveats

Matches format, not meaning — 0.0.0.0 and broadcast addresses pass. For subnet logic (is this IP in 10.0.0.0/8?), use a CIDR calculator, not a regex.

Matches

  • 192.168.1.1
  • 10.0.1.37
  • 255.255.255.255
  • 8.8.8.8

Doesn't match

  • 256.1.1.1
  • 192.168.01.1
  • 1.2.3
  • 1.2.3.4.5

More patterns