IPv6 Address in JS
Match full (non-compressed) IPv6 addresses written as eight colon-separated hextets.
Try it in the JS tester →Pattern
regexJS
(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4} (flags: g)JavaScript / ECMAScript code
jsJavaScript
const re = new RegExp("(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}", "g");
const input = "2001:0db8:85a3:0000:0000:8a2e:0370:7334";
const matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));Uses `String.prototype.matchAll` for global iteration (Node 12+ / all modern browsers).
How the pattern works
Seven groups of 1–4 hex digits each followed by a colon, then a final hextet. Does not cover :: shorthand or IPv4-mapped addresses — use a more complex pattern if you need those forms.
Examples
Input
2001:0db8:85a3:0000:0000:8a2e:0370:7334Matches
2001:0db8:85a3:0000:0000:8a2e:0370:7334
Input
::1No match
—