Regular expression that matches valid IPv6 addresses

I’m having trouble writing a regular expression that matches valid IPv6 addresses, including those in their compressed form (with :: or leading zeros omitted from each byte pair).

Can someone suggest a regular expression that would fulfill the requirement?

I’m considering expanding each byte pair and matching the result with a simpler regex.

Leave a Comment