IPv4 regex pattern

Copy and test a JavaScript regex for IPv4 addresses, with examples and a one-click link to the regex tester.

IPv4 regex pattern

Validate whole value

Use anchors to check whether the complete value matches.

Regex: ^(?:25[0-5]|2[0-4]\d|1?\d?\d)(?:\.(?:25[0-5]|2[0-4]\d|1?\d?\d)){3}$

Flags: -

Search in text

Find matching fragments inside a larger block of text.

Regex: \b(?:25[0-5]|2[0-4]\d|1?\d?\d)(?:\.(?:25[0-5]|2[0-4]\d|1?\d?\d)){3}\b

Flags: g

Examples that match

  • 192.168.0.1
  • 10.0.0.254

Examples that do not match

  • 999.1.1.1
  • 192.168.1