I'm looking for a regular expression for grep that filters out IPv4 and IPv6 addresses from an arbitrary file containing them. I'd like it to behave like this one for IPv4 addresses:
grep -E -o "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)" I'm aware there are several similar questions with answers here but most focus on just IPv4 addresses and the best answer I've found does not work for me. The expression does not output any IP address for me when using grep.
As this question is apparently ambiguous, I'm looking for a combined regex. One that will output any valid IP address. As a bonus, even multiple ones on a single line.
If for some reason this is not easy to do with grep, I'm open to alternatives, provided they are simple, work on a BSD system and do not require GNU tools.
8.8.2056a valid IPv4 address? Are leading zeroes allowed or should they be normalized away? Must or must not::be used in IPv6?). If you want a validating expression, you need to specify what counts a valid.inet_pton()or equivalent.