← Back to all regex patterns
Validation
Low backtracking risk

Regex for IPv4 Address

Use this when you need to validate dotted IPv4 literals and reject octets outside the 0-255 range.

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

Try this pattern

Matches current input
192.168.1.10

1 match found in the current text.

Passing examples

  • 192.168.1.10
  • 8.8.8.8

Failing examples

  • 999.10.0.1
  • 10.0.0

Code examples

JavaScript
const regex = /^(?:25[0-5]|2[0-4]\d|1?\d?\d)(?:\.(?:25[0-5]|2[0-4]\d|1?\d?\d)){3}$/g;
regex.test(input);
Python
import re
pattern = re.compile(r"^(?:25[0-5]|2[0-4]\d|1?\d?\d)(?:\.(?:25[0-5]|2[0-4]\d|1?\d?\d)){3}$")
bool(pattern.search(input))
Go
re := regexp.MustCompile("^(?:25[0-5]|2[0-4]\\d|1?\\d?\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1?\\d?\\d)){3}$")
matched := re.MatchString(input)

Related Validation Patterns