DevTools
Back to Regex Tester

IPv4 Address Regex Pattern

Validate IPv4 addresses (0.0.0.0 to 255.255.255.255) with regex. Includes boundary checking and ready-to-use patterns.

The Pattern

/\b(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\b/g

How It Works

TokenMeaning
\bWord boundary to prevent partial matches
25[0-5]Matches 250-255
2[0-4]\dMatches 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)

Test Cases

192.168.1.1Match
10.0.0.255Match
255.255.255.0Match
0.0.0.0Match
999.999.999.999No match
256.1.1.1No match

Code Examples

javascript
const 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"]
python
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']

Common Use Cases

Related Patterns

Want to test this pattern with your own data?

Try this pattern in Regex Tester →