IPv4 address regex
Four numbers from 0 to 255 separated by dots, written without leading zeros. Copy the pattern, with 4 inputs it accepts and 6 it rejects, each checked against it at build time.
Part of developer tools.
^(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)$/^(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)$/Flags: none
Open in the testerWhat the ipv4 address regex accepts and rejects
Each result below is the output of the pattern itself, run on the input when this page was built — not a claim copied next to it. A wrong verdict stops the build.
| Input | Result | Why |
|---|---|---|
| 192.168.1.1 | Passes | a private address |
| 8.8.8.8 | Passes | single-digit octets |
| 255.255.255.255 | Passes | the upper bound of every octet |
| 0.0.0.0 | Passes | the lower bound |
| 256.1.1.1 | Fails | an octet above 255 |
| 192.168.1 | Fails | three octets |
| 192.168.01.1 | Fails | a leading zero |
| 1.2.3.4.5 | Fails | five octets |
| 192.168.1.1/24 | Fails | CIDR notation |
| 10.0.0.1:8080 | Fails | a port |
Limits
- Every syntactically valid address passes, including reserved, private, loopback and broadcast ones. Whether 127.0.0.1 or 10.x is acceptable in your context is a separate check.
- Leading zeros are refused on purpose: some parsers read 010 as octal 8, so 192.168.010.1 is ambiguous rather than merely unusual.
- IPv6 needs its own, much longer pattern; this one refuses every IPv6 address, including IPv4-mapped ones like ::ffff:192.168.1.1.
Try it on your own input
Open this pattern in the regex tester with every example above on its own line. The link adds the g and m flags so that ^ and $ hold per line and every line is tested: the highlighted lines are the ones marked as passing here. Paste your own data in place of the examples — it is matched in your browser and never uploaded.
Other common regexes
- Email address
- URL
- UUID
- Hex color
- ISO 8601 date
- 24-hour time
- Semantic version
- URL slug
- Phone number (E.164)
- US ZIP code
- MAC address
Or open the regex tester empty and bring your own pattern.