IPv4 Regex Example
Match IPv4 addresses with strict 0-255 octet validation for each of four segments.
This IPv4 regex example validates dotted decimal IPv4 addresses while constraining each octet to 0-255. It avoids overly broad patterns that accept invalid values such as 999.1.1.1, which makes it useful for config forms, firewall rule editors, and infrastructure tooling UIs. The expression repeats a validated octet segment exactly four times with dot separators, giving predictable behavior and easy test coverage. It is a format validator only: it does not determine whether an address is routable, private, reserved, or currently active on a network. Use it as a frontend or parser pre-check, then apply network-aware logic where needed. You can test this regex with real subnet examples and pair it with the IP Subnet Calculator for broader networking workflows.
Pattern
/^(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}$/Matches
192.168.1.10
8.8.8.8
10.0.0.254
Rejects
256.1.1.1
192.168.1
abc.def.ghi.jkl
FAQ
Does this regex validate IPv6 addresses?
No. It is specific to IPv4 dotted decimal notation.
Can I block private ranges with regex alone?
You can, but it is clearer to parse the IP and apply explicit range checks in code.
Why not use a simpler pattern for IPv4?
Simpler patterns often accept invalid octet values. This version keeps strict octet bounds.
Related: Regex Tester & Generator, Text Diff Checker, JSON vs YAML guide.
Browse all patterns in the regex examples hub.
More regex examples
Email Regex Example - Validate common email-like strings with a practical pattern suitable for frontend form checks.
Phone Number Regex Example - Match normalized phone numbers with optional plus prefix and 7 to 15 digits.
Password Regex Example - Require uppercase, lowercase, number, symbol, and a minimum length for strong-password policies.
URL Regex Example - Validate common HTTP/HTTPS URLs including optional ports, paths, and query fragments.