Note that regular expressions are not really meant for parsing things like IPv4 addresses. You can try to do it, to a certain level of accuracy:
Your expression \d+\.\d+\.\d+\.\d+
would match any four groups of digits separated by a dot, if \d
matched a digit on its own.
Keep in mind that regular expressions have many flavors and results may vary, depending on the engine being used. When you use grep -P
as suggested in another answer, you change the parsing engine.
In Matching IPv4 Addresses - Regular Expressions Cookbook by O'Reilly you have some examples.
This checks for (just) an IP address, not many checks though, 299.299.111.1
would pass:
^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$
The other examples in the page try to narrow down the detection to get a valid IP address, see what they propose for accurate extraction from longer text and you'll know why IPv4 addresses are not a good playground for regular expressions:
\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}↵
(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b
+
quantifier is part of the extended regular expression syntax and\d
is from the perl (PCRE) extension set – steeldriver Jan 10 '21 at 18:29grep
to understand\d
as "a digit", you still would match e.g.000.0002222.020202020.020.0.0.0.0.0
with that expression. – Kusalananda Jan 10 '21 at 18:53