Validate IPv4 addresses (0.0.0.0 to 255.255.255.255) with regex. Includes boundary checking and ready-to-use patterns.
/\b(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\b/g| Token | Meaning |
|---|---|
\b | Word boundary to prevent partial matches |
25[0-5] | Matches 250-255 |
2[0-4]\d | Matches 200-249 |
[01]?\d\d? | Matches 0-199 |
\.) | Literal dot between octets |
{3} | Repeat first three octets with dots |
(?:25[0-5]|2[0-4]\d|[01]?\d\d?) | Final octet (same range, no trailing dot) |
192.168.1.1Match10.0.0.255Match255.255.255.0Match0.0.0.0Match999.999.999.999No match256.1.1.1No matchconst ipRegex = /\b(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\b/g;
const text = "Server IPs: 192.168.1.1, 10.0.0.255, invalid 999.999.999.999";
const matches = text.match(ipRegex);
console.log(matches); // ["192.168.1.1", "10.0.0.255"]import re
ip_regex = r'\b(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\b'
text = "Server IPs: 192.168.1.1, 10.0.0.255, invalid 999.999.999.999"
matches = re.findall(ip_regex, text)
print(matches) # ['192.168.1.1', '10.0.0.255']Want to test this pattern with your own data?
Try this pattern in Regex Tester →