Regex for IPv4 Address
Matches valid IPv4 addresses (0.0.0.0 to 255.255.255.255) with proper octet range validation.
Pattern
/^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/Pattern Breakdown
| Token | Explanation |
|---|---|
| ^ | Start of string |
| (?:25[0-5]|2[0-4]\d|[01]?\d\d?) | Octet: 0-255 |
| \. | Literal dot separator |
| {3} | Repeat first three octets with dots |
| (?:25[0-5]|2[0-4]\d|[01]?\d\d?) | Fourth octet: 0-255 |
| $ | End of string |
Test Examples
| Input | Match? |
|---|---|
| 192.168.1.1 | Match |
| 0.0.0.0 | Match |
| 255.255.255.255 | Match |
| 256.1.1.1 | No match |
| 192.168.1 | No match |
Common Use Cases
- Network configuration validation
- Firewall rule input
- Log parsing
- Server configuration
Variations
\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\bSimpler (no range validation)
Other Regex Patterns
Want to test this pattern with your own data?
Open the Regex Tester