IP Address Regex Tester
Test and validate ip patterns with this specialized regex tester. Includes tested patterns and real-time matching.
Recommended Ip Pattern
``regex
^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$
`
Test Examples
Valid matches:
- 192.168.1.1
10.0.0.255255.255.255.00.0.0.0
Invalid (should not match):
256.1.1.1192.168.1192.168.1.1.1192.168.1.999
Pattern Explanation
Matches valid IPv4 addresses (0-255 for each octet)
Alternative Patterns
1. ^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$
How to Use
1. The pattern above is preloadedβor enter your own
2. Add test strings to validate
3. See real-time match highlights
4. Copy the pattern for your code
Regex Quick Reference
| Symbol | Meaning | Example | ||
|---|---|---|---|---|
| \d | Any digit | \d{3} matches "123" | ||
| \w | Word character | \w+ matches "hello" | ||
| + | One or more | a+ matches "aaa" | ||
| * | Zero or more | a* matches "" or "aaa" | ||
| ? | Optional | colou?r matches "color" | ||
| ^ | Start of string | ^Hello | ||
| $ | End of string | world$ | ||
| [abc] | Character class | [aeiou] matches vowels | ||
| (a | b) | Alternation | (cat | dog) matches either |
The Pattern
`regex
^(?:(?: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: gm β m makes ^ and $ match at each line break, so the pattern can be tested against a list.
Broken Down
| Part | What it does |
|---|---|
25[0-5] | 250β255 |
2[0-4]\d | 200β249 |
1\d\d | 100β199 |
[1-9]?\d | 0β99 |
Tested Against Real Input
| Input | Result |
|---|---|
192.168.1.1 | β matches |
8.8.8.8 | β matches |
255.255.255.255 | β matches |
256.1.1.1 | β no match |
1.2.3 | β no match |
The Important Caveat
The alternation exists because \d{1,3} would happily accept 999.999.999.999. This pattern is IPv4 only; IPv6 needs a different and considerably longer one.
Using It
`javascript
const pattern = /^(?:(?: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)$/gm;
// Test a single value β reset lastIndex first if the pattern is global
pattern.lastIndex = 0;
const isValid = pattern.test(value);
// Or find every match in a block of text
const matches = [...text.matchAll(pattern)];
`
A global regex carries lastIndex between calls, so reusing one across test() calls
returns alternating results. Either drop the g flag for validation or reset it each time.
Anchors, Greediness and Backtracking
Three behaviours account for most regex surprises, and this pattern shows all three.
Anchors. ^ and $ pin the match to the start and end of the input. Without them,
\d{3} matches the 123 inside abc123def. With m in the flags β as here β they
pin to each *line* instead, which is what lets one pattern be tested against a list.
Greediness. .* takes as much as it can and gives back only when forced; .*? takes
as little as possible. On , the pattern <.*> matches the whole string and
<.*?> matches just .