IPv4 Address Validation Regex
Validate IPv4 addresses with proper range checking. Matches addresses from 0.0.0.0 to 255.255.255.255.
Pattern & Test String
About This Pattern
Pattern: ^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$
Flags: g
Results
Enter a regex pattern to see the results here.
Frequently Asked Questions
Does this pattern validate the numeric range?
Yes, this pattern ensures each octet is between 0-255, preventing invalid IPs like 256.300.1.1.
Will this match IPv6 addresses?
No, this is specifically for IPv4. IPv6 uses hexadecimal notation and colons, requiring a completely different pattern.
Does it accept leading zeros like 192.168.001.001?
Yes, this pattern accepts leading zeros. To reject them, modify the pattern to not allow [01]? before single digits in certain contexts.
Practical Examples
Network Configuration Validation
Validate IP addresses in network configuration forms or scripts.
Log File Parsing
Extract IP addresses from server logs for security analysis.
Access Control
Validate IP addresses for whitelist/blacklist implementations.
Common Issues & Solutions
Remember that 0.0.0.0 and 255.255.255.255 are valid but have special meanings (any address and broadcast).
Private IP ranges (10.x.x.x, 172.16-31.x.x, 192.168.x.x) are syntactically valid but may need additional logic to identify.
This pattern doesn't validate CIDR notation (192.168.1.0/24). Add /\d{1,2} at the end if needed.