Regex pattern
IPv4 Regex — free online tester
Strictly match IPv4 addresses — rejects out-of-range octets like 256.0.0.1 that simpler patterns let through.
The pattern
\b(?:(?:25[0-5]|2[0-4]\d|[01]?\d{1,2})\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d{1,2})\b/gHow it works
A naive `\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}` regex matches 999.999.999.999 — clearly wrong. This stricter version uses alternation per octet (0–255) so only valid IPv4 addresses match. Word boundaries on both ends prevent it from matching inside longer numbers.
When to use it
- ▸Parse IPs from access logs (nginx, Apache, application logs)
- ▸Extract suspicious IPs from a fail2ban report
- ▸Validate user-supplied IP addresses in configs
- ▸Filter ranges in firewall / CDN rule preview
Tip
This matches every IPv4 address but doesn't enforce CIDR notation or distinguish public from private (RFC 1918) ranges — add another filter for that.
Try it on this input
Server: 192.168.1.1 Gateway: 10.0.0.1 DNS: 8.8.8.8 and 8.8.4.4 Public test: 93.184.216.34 (example.com) Loopback: 127.0.0.1 Not valid: 300.1.1.1, 256.0.0.0, 1.2.3, 999.999.999.999
What this pattern doesn't catch
- ⚠Does not validate or extract CIDR suffixes (e.g. /24 not matched)
- ⚠No distinction between public, private, and reserved ranges
- ⚠Won't catch IPv6 addresses — use a separate pattern for those
More regex patterns
Email Regex
A practical email-validation regex that catches the 99% case without choking on every RFC edge case.
URL Regex
Extract every http(s) URL from a block of text — captures protocol, domain, path, query string, and fragment.
Phone Number Regex
Match US / Canada phone numbers in every common written format — with or without country code.
Date Regex (ISO 8601)
Match ISO 8601 dates (YYYY-MM-DD) and optionally times in any text — the format JSON APIs, databases, and logs use.
UUID Regex
Strict UUID pattern — validates version (1–7) and variant nibbles so random hex strings don't pass.
Credit Card Regex
Match credit-card numbers from major networks (Visa, Mastercard, Amex, Discover) for extraction or redaction.
Full Regex Tester →
Cheatsheet · pattern builder · cross-language translation · replace · explain · history
