Skip to content

Regex for IPv6 Address

This regex matches standard IPv6 addresses in their full notation with eight groups of four hexadecimal digits separated by colons. IPv6 is the successor to IPv4, providing a vastly larger address space. This pattern matches the expanded form of IPv6 addresses, which is the most explicit representation used in configuration files and documentation.

Pattern flags: i
^(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$
Test this pattern in the Regex Tester →

What is the regex pattern for IPv6 Address?

The regex pattern for IPv6 Address is ^(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$ with the i flag. This regex matches standard IPv6 addresses in their full notation with eight groups of four hexadecimal digits separated by colons. IPv6 is the successor to IPv4, providing a vastly larger address space. This pattern matches the expanded form of IPv6 addresses, which is the most explicit representation used in configuration files and documentation. This pattern is commonly used for network configuration validation and dns record validation.

Test Examples

Match
2001:0db8:85a3:0000:0000:8a2e:0370:7334
Matches: 2001:0db8:85a3:0000:0000:8a2e:0370:7334
Match
fe80:0000:0000:0000:0000:0000:0000:0001
Matches: fe80:0000:0000:0000:0000:0000:0000:0001
No Match
not:an:ipv6

Common Uses

Variations

With shorthand (::)

^(([0-9a-fA-F]{1,4}:){0,6}[0-9a-fA-F]{1,4})?(::)(([0-9a-fA-F]{1,4}:){0,6}[0-9a-fA-F]{1,4})?$

Allows :: shorthand for consecutive zero groups

IPv6 with IPv4 suffix

^([0-9a-fA-F]{1,4}:){6}(\d{1,3}\.){3}\d{1,3}$

Matches mixed notation like ::ffff:192.168.1.1

Loopback address

^::1$

Matches only the IPv6 loopback address

Frequently Asked Questions

Why does this not match shortened IPv6 addresses?

The base pattern matches only full-form addresses with all eight groups. IPv6 allows shortening with :: to represent consecutive zero groups, which makes the regex significantly more complex. Use the 'With shorthand' variation for that.

How many addresses does IPv6 support?

IPv6 uses 128-bit addresses, providing approximately 340 undecillion (3.4 x 10^38) unique addresses. This is vastly more than IPv4's approximately 4.3 billion addresses.

When should I validate IPv6 addresses with regex?

Use regex for quick format checks in forms or log parsers. For production network code, use your language's built-in IP address parsing library, which handles all valid representations including compressed and mixed notation.

Related Patterns

IPv4 Address

^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3...

Domain Name

^(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-z...

Hex Color Code

^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-...

Related Reading

Regex Cheat Sheet with Examples for Developers → URL Encoding Special Characters →