3 ms·
> :g/\(\d\{1,3}\.\)\{3}\d\{1,3\}/y A This is IPv4 only. Have one for v6 as well?
by mvanbaak 3y ago
> :g/\(\d\{1,3}\.\)\{3}\d\{1,3\}/y A
This is IPv4 only. Have one for v6 as well?
- beaugunderson 3y agoBecause empty octets of an IPv6 address can be elided (1:0:0:0:0:0:0:2 can be represented as 1::2) the regular expressions are actually quite painful. I wrote a library for JavaScript called `ip-address` that can generate regular expressions to find all forms of a specific address. Here's the regular expression for all forms of 1::2: /(?=^|[^A-Fa-f0-9:]|[^\w\:])((0{0,3}1):(|(:0{1,4}){1,5}|(0{1,4}:){1,5}|(0{1,4}:){5}0{1,4}|(0{1,4}:){1}:(0{1,4}:){3}0{1,4}|(0{1,4}:){2}:(0{1,4}:){2}0{1,4}|(0{1,4}:){3}:(0{1,4}:){1}0{1,4}|(0{1,4}:){4}:(0{1,4}:){0}0{1,4}|(0{1,4}:){1}:(0{1,4}:){2}0{1,4}|(0{1,4}:){2}:(0{1,4}:){1}0{1,4}|(0{1,4}:){3}:(0{1,4}:){0}0{1,4}|(0{1,4}:){1}:(0{1,4}:){1}0{1,4}|(0{1,4}:){2}:(0{1,4}:){0}0{1,4}|(0{1,4}:){1}:(0{1,4}:){0}0{1,4}):(0{0,3}2))(?=[^\w\:]|[^A-Fa-f0-9:]|$)/i