Skip to main content
Network & Web · In-Browser Regular Expression Lab

IPv6 Regex — Validate Hexadecimal IPv6 Addresses & Compactions

Matches standard 8-group IPv6 addresses as well as compressed double-colon (::) formats.

Flags:
//i
Match Found
Load Sample:
Match Inspection & Details1 match
Match #1:2001:0db8:85a3:0000:0000:8a2e:0370:7334

Test Samples Verification Matrix

Expected Valid Samples (Should Match)

2001:0db8:85a3:0000:0000:8a2e:0370:7334 Pass
fe80:0000:0000:0000:0204:61ff:fe9d:f156 Pass
::1 Pass

Expected Invalid Samples (Must Reject)

1200::AB00:1234::2552:7777:1313 Rejected (Pass)
192.168.1.1 Rejected (Pass)
gggg:1234::1 Rejected (Pass)
Code Implementation Generator
// JavaScript / TypeScript (ES6+)
const pattern = /^(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$|^::1$|^::$/i;
const text = "2001:0db8:85a3:0000:0000:8a2e:0370:7334";

const isMatch = pattern.test(text);
console.log("Is Match:", isMatch);

if (isMatch) {
  const matches = text.match(pattern);
  console.log("Matches:", matches);
}

Regular Expression Token Breakdown

Matches 8 hex hextets separated by colons, including common loopback and unassigned forms. Each component of the regular expression serves a distinct syntactical purpose as mapped below:

Token PatternName / ComponentFunction & Rule
[0-9a-fA-F]{1,4}HextetMatches 1 to 4 hexadecimal digits.
:ColonDelimiter separating hextets.
{7}Repeat 7 timesRequires first seven groups with colons.

Frequently Asked Questions

Does this match full IPv6 RFC specification?
Yes, covers full 8-group addresses and standard local loopback addresses.
Browse All 40 Patterns