IPv6 regex pattern

Copy and test a JavaScript regex for IPv6 addresses, with examples, limitations, and a one-click link to the regex tester.

IPv6 regex pattern

Validate whole value

Use anchors to check whether the complete value matches.

Regex: ^(?:(?:[0-9a-f]{1,4}:){7}[0-9a-f]{1,4}|(?:[0-9a-f]{1,4}:){1,6}:[0-9a-f]{1,4}|(?:[0-9a-f]{1,4}:){1,7}:|:(?::[0-9a-f]{1,4}){1,7})$

Flags: i

Search in text

Find matching fragments inside a larger block of text.

Regex: (?:(?:[0-9a-f]{1,4}:){7}[0-9a-f]{1,4}|(?:[0-9a-f]{1,4}:){1,6}:[0-9a-f]{1,4}|(?:[0-9a-f]{1,4}:){1,7}:|:(?::[0-9a-f]{1,4}){1,7})

Flags: gi

Examples that match

  • 2001:0db8:85a3:0000:0000:8a2e:0370:7334
  • fe80::1

Examples that do not match

  • 2001:::7334
  • 192.168.0.1

Limitations

This practical pattern covers common IPv6 forms but not every rare representation such as IPv4-mapped variants.