Networkingflags: g
IPv6 Address
Match full (non-compressed) IPv6 addresses written as eight colon-separated hextets.
Try it in RegexPro →Available in
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).
Python (re) code
pyPython
import re
pattern = re.compile(r"(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}")
input_text = "2001:0db8:85a3:0000:0000:8a2e:0370:7334"
for m in pattern.finditer(input_text):
print(m.group(0))Stdlib `re` module — no third-party dependency. Works on Python 3.6+.
Go (RE2) code
goGo
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}`)
input := `2001:0db8:85a3:0000:0000:8a2e:0370:7334`
for _, match := range re.FindAllString(input, -1) {
fmt.Println(match)
}
}Uses `regexp.MustCompile` (panics on bad patterns at startup) and `FindAllString` for all matches.
Pattern
regexengine-agnostic
(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4} (flags: g)Raw source: (?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}
How it 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
—Common use cases
- •Network log parsing
- •Firewall rule generation
- •IPv6 adoption auditing
- •Dual-stack inventory tooling
Related patterns
MAC Address
NetworkingMatch 48-bit MAC addresses written with colon or hyphen separators (e.g. 00:1A:2B:3C:4D:5E).
IP Address with CIDR Notation
NetworkingMatch IPv4 addresses with CIDR prefix notation such as 10.0.0.0/8 or 192.168.1.0/24.
IPv4 Address
NetworkingMatch valid IPv4 addresses with each octet constrained to 0–255.
Private IP Address (RFC 1918)
NetworkingMatch IPv4 addresses in the RFC 1918 private ranges: 10/8, 192.168/16, and 172.16/12.