What Is This?
This regex pattern matches IPv4 addresses in dotted-decimal notation. It validates the format of four octets (0-255) separated by dots. Note: this validates the format but does not check that each octet is in the valid range 0-255 — a full validation also requires numeric range checking.
How to Use
The Pattern
The pattern matches four groups of 1-3 digits separated by dots. After matching with regex, validate numerically that each octet is between 0 and 255. Use this pattern for log parsing, configuration validation, and network tool input filtering.
/^(?:\d{1,3}\.){3}\d{1,3}$/Examples
Valid IPv4 addresses
Matches: 192.168.1.1 10.0.0.1 8.8.8.8 255.255.255.0 Does not match: 256.1.2.3 192.168.1 192.168.1.1.1
Edge cases
Matches: 0.0.0.0 127.0.0.1 172.16.254.1 Does not match: abc.def.ghi.jkl 192.168.1.255 . . .
Frequently Asked Questions
How do I validate octet ranges with regex?
The full regex for valid IPv4 ranges (0-255) is: ^(?: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)$. This validates each octet is between 0 and 255.
Does this match IPv6 addresses?
No. IPv6 uses colon-separated hexadecimal notation (e.g., 2001:0db8:85a3:0000:0000:8a2e:0370:7334). IPv6 requires a completely different pattern.