Regex to Match an IPv4 Address
Copy the pattern, paste your log text below, and watch it highlight every IPv4 address. Below the tester: how each octet is bounded to 0–255.
What this pattern matches
This expression matches a full IPv4 address — four octets separated by dots — and rejects any octet above 255, so 256.1.1.1 will not match.
How it works, part by part
(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d) — one octet: 250–255, or 200–249, or 100–199, or 0–99.
(?:…\.){3} — that octet followed by a dot, repeated three times.
\b — word boundaries so it does not match inside a longer number.
IPv4 only
This does not match IPv6 addresses like 2001:db8::1, which use a different notation. Match those with a separate IPv6 pattern.
FAQ
Does it reject octets over 255?
Yes. Each octet group caps at 255, so 256.1.1.1 does not match.
Will it match an IP embedded in a longer number?
No. The \b word boundaries stop it matching inside something like 9192.168.0.1.
Does it match IPv6?
No. IPv6 uses colon-separated hex groups and needs its own pattern.