T
ToolPrime

Regex for IPv6 Address

Validates full IPv6 addresses (eight groups of four hexadecimal digits).

Pattern

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

Live Tester

Enter a string to test

Examples

The i flag makes the pattern case-insensitive.

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

Pattern Breakdown

([0-9a-fA-F]{1,4}:){7} — seven groups of 1-4 hex digits followed by colon

[0-9a-fA-F]{1,4}$ — final group without trailing colon

Code Snippets

Javascript

const regex = /^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$/i;
regex.test("2001:0db8:85a3:0000:0000:8a2e:0370:7334"); // true

Python

import re
pattern = r"^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$"
bool(re.match(pattern, "2001:0db8:85a3:0000:0000:8a2e:0370:7334", re.IGNORECASE))  # True

Php

$pattern = '/^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$/i';
preg_match($pattern, "2001:0db8:85a3:0000:0000:8a2e:0370:7334"); // 1

Related Patterns

Frequently Asked Questions

What is the regex for IPv6 Address?
The regex pattern for IPv6 Address is /^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$/i. Validates full IPv6 addresses (eight groups of four hexadecimal digits).
How do I use the IPv6 Address regex in JavaScript?
In JavaScript you create the pattern with a regex literal or the RegExp constructor and call .test() to check a string against it. A ready-to-copy example is shown in the Code Snippets section above, alongside Python and PHP versions.
What does the IPv6 Address pattern match?
It matches strings like 2001:0db8:85a3:0000:0000:8a2e:0370:7334; it rejects strings like 2001:db8::1. See the Examples section above for the full list of matching and non-matching cases.

Related Tools