# Regex for IPv6 Address Validation

> IPv6 regex for full eight-group addresses, why compressed :: forms need a parser, and the breakdown of the pattern's tokens.

```
/^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$/
```

A full IPv6 address is eight groups of 1–4 hex digits separated by colons, and that's what this pattern validates. The honest caveat: IPv6's :: compression (dropping runs of zero groups) makes a complete regex enormous and easy to get subtly wrong — if you need to accept ::1 or 2001:db8::7334, expand the address first or use a real parser.

## Token by token

| Token | Meaning |
|---|---|
| `^(` | start of string, open the repeating group |
| `[0-9a-fA-F]{1,4}` | one group: 1 to 4 hex digits (leading zeros optional) |
| `:){7}` | a colon after the group — seven times |
| `[0-9a-fA-F]{1,4}$` | the eighth group, then end of string |

## Examples

- ✓ matches: `2001:0db8:85a3:0000:0000:8a2e:0370:7334`
- ✓ matches: `fe80:0:0:0:0:0:0:1`
- ✓ matches: `2001:db8:85a3:0:0:8a2e:370:7334`
- ✗ does not match: `::1`
- ✗ does not match: `2001:db8`
- ✗ does not match: `g001:db8:85a3:0:0:8a2e:370:7334`

## Variations

- `^::1$|^::$` — just the loopback and unspecified addresses — the two compressed forms worth special-casing
- `^([0-9a-fA-F]{1,4}:){1,7}:$` — addresses ending in :: (trailing zero groups compressed)

## Language notes

- Prefer a parser for anything user-facing: net.ParseIP in Go, ipaddress.IPv6Address in Python, and the URL host parser in browsers all handle compression correctly.
- The complete compressed-form regex runs to hundreds of characters with eight alternations — it exists, but nobody can review it.

## FAQ

### Why doesn't this match ::1?

::1 uses zero compression — the :: stands in for seven zero groups. Supporting every compressed position roughly squares the pattern's complexity, which is why this page validates full form and recommends expanding or parsing compressed input.

### How do I normalize an IPv6 address to full form?

Use the standard library: ipaddress.IPv6Address(s).exploded in Python gives the full eight-group form; most languages have an equivalent. Then this pattern (or simple string logic) applies cleanly.

## Related patterns

- [Regex for IPv4 Address Validation](https://www.devkult.com/regex/ipv4.md)
- [Regex for URL Validation](https://www.devkult.com/regex/url.md)
- [Regex for UUID Validation](https://www.devkult.com/regex/uuid.md)

Open the interactive page: https://www.devkult.com/regex/ipv6