.*RegexQuick
IP Address Regex
Regex for validating IPv4 and IPv6 addresses. Handles all valid formats with proper range checking.
^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}$//
0 matches
About this pattern
The IPv4 pattern validates each octet is between 0 and 255 by checking three ranges: 250-255 (25[0-5]), 200-249 (2[0-4]\d), and 0-199 (1\d\d|[1-9]?\d). The octets are separated by dots and the pattern repeats exactly 4 times. This is one of the more complex common regex patterns because simple \d{1,3} would match invalid values like 999.
Worked examples
Each octet is range-checked, so 256.1.1.1 is rejected — a naive \d{1,3} pattern would wrongly accept it.
Matches
- 192.168.1.1
- 8.8.8.8
- 255.255.255.255
- 0.0.0.0
Does not match
- 256.1.1.1
- 1.2.3
- 1.2.3.4.5
- 999.999.999.999
FAQ
Why not just use \d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}?
Because that matches invalid IPs like 999.999.999.999. Each octet must be 0-255, which requires the alternation pattern shown above.