IP Address Regex (IPv4 / IPv6) Generator & Tester
Copy a tested regex for IPv4 (0–255), IPv4 CIDR, private ranges or full IPv6 (compressed, IPv4-mapped), test lines, or pull every IP out of a log.
Parts with a leading zero (010) are rejected: inet_aton, ping and many browsers read them as octal, so 010.0.0.1 means 8.0.0.1.
| Line | Value | Result | Type or reason |
|---|---|---|---|
| 1 | 192.168.1.1 | Match | IPv4 |
| 2 | 255.255.255.255 | Match | IPv4 |
| 3 | 256.1.1.1 | No match | 256 is above 255 |
| 4 | 10.0.0 | No match | An IPv4 address has 4 parts, this has 3 |
| 5 | 010.0.0.1 | No match | Leading zero (often read as octal) |
| 6 | 2001:db8::1 | No match | This is an IPv6 address |
| 7 | ::ffff:192.0.2.128 | No match | This is an IPv6 address |
| 8 | fe80::1%eth0 | No match | Zone index (%…) not allowed — tick the option |
| 9 | 2001:db8:::1 | No match | ":::" is not allowed |
Checking an IP address with a regex sounds simple until 999.1.1.1 slips through or a compressed IPv6 address such as ::ffff:192.0.2.128 is rejected. This tool gives you exact patterns — IPv4 with every part limited to 0–255, IPv4 CIDR blocks, private RFC 1918 ranges, and IPv6 in all its legal forms — with code for JavaScript, PHP, Python, Java and C#. Test them line by line with a reason for each failure, or pull every address out of a log file.
How to use this tool
- Choose what to match: IPv4, CIDR, private ranges, IPv6 or both.
- Decide on leading zeros and IPv6 zone indexes.
- Pick the language and whether you validate values or search text.
- Paste test values or a log and check the results.
Formula
IPv4 part: 25[0-5] | 2[0-4][0-9] | 1[0-9]{2} | [1-9]?[0-9] · IPv6: 8 groups of 1–4 hex digits, with one "::" standing for missing zero groups
The IPv4 part pattern lists 250–255, 200–249, 100–199 and 0–99 separately, so 256 cannot match. The IPv6 pattern is written straight from the RFC 3986 grammar: nine alternatives, one for each position of "::", with an IPv4 tail allowed in the last 32 bits (RFC 4291). Private ranges are 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16. When searching text, matches may not touch other digits, so 1.2.3.4.5 and version numbers are skipped, while a full stop at the end of a sentence is fine.
Example
In the sample list, 192.168.1.1 and 255.255.255.255 match the IPv4 pattern. 256.1.1.1 fails (256 is above 255), 10.0.0 has only three parts, 010.0.0.1 has a leading zero, and the IPv6 lines are not IPv4. Switched to IPv6, 2001:db8::1 and ::ffff:192.0.2.128 match while 2001:db8:::1 fails because ":::" is not allowed.
Frequently asked questions
Why reject 010.0.0.1?
Many C libraries, ping and some URL parsers read a part with a leading zero as octal, so 010 means 8. Rejecting them avoids an address being read two different ways. Tick the option if your data really uses zero-padded parts.
Does the IPv6 pattern accept upper-case letters?
Yes. Both cases are valid input; RFC 5952 only recommends writing lower case.
Can a regex tell whether an address is public?
Only by listing ranges, as the private option does for RFC 1918. For anything more (reserved, documentation or multicast blocks), parse the address with a library.
Sources
Last updated:
Page address with these inputs: https://kakao.mobile/tools/ip-regex-tool/
Cite or embed this tool
kakaoCalc. (2026, November 8). IP Address Regex (IPv4 / IPv6) Generator & Tester. https://kakao.mobile/tools/ip-regex-tool/
“IP Address Regex (IPv4 / IPv6) Generator & Tester.” kakaoCalc, 8 Nov. 2026, kakao.mobile/tools/ip-regex-tool/.
Paste this code into your page. The widget runs in your visitors' browsers, shows no ads and keeps a link back to this page. Embedding terms