IPv6 Link-Local Address Regex for Go
/^[Ff][Ee][89AaBb][0-9a-fA-F](?::[0-9a-fA-F]{0,4}){0,7}(?:%[a-zA-Z0-9_.-]{1,20})?$/What this pattern does
This page provides a comprehensive, battle-tested regular expression for matching ipv6 link-local address, ported and verified for Go. A rigorously tested regex reduces debugging time and protects your application from edge-case failures. The snippet below is ready to drop into your Go project — whether you're validating in a Gin handler, a gRPC service, or a command-line tool.
Go Implementation
// IPv6 Link-Local Address
// ReDoS-safe | RegexVault — Web & Network > IPv6
package validation
import "regexp"
var ipv6LinklocalAddressRe = regexp.MustCompile(`^[Ff][Ee][89AaBb][0-9a-fA-F](?::[0-9a-fA-F]{0,4}){0,7}(?:%[a-zA-Z0-9_.-]{1,20})?$`)
func ValidateIpv6LinklocalAddress(s string) bool {
return ipv6LinklocalAddressRe.MatchString(s)
}
// Example
// fmt.Println(ValidateIpv6LinklocalAddress("fe80::1")) // trueTest Cases
Matches (Valid) | Rejects (Invalid) |
|---|---|
fe80::1 | fc00::1 |
fe80::1%eth0 | 2001:db8::1 |
fe80::a1b2:c3d4:e5f6:0001 | ::1 |
fe80::1%lo0 | fe80::1% |
FE80::1%en0 | fe70::1 |
When to use this pattern
This pattern is drawn from the Web & Network > IPv6 category and carries a ReDoS-safe certification. That matters for Go developers because Go's RE2 engine is inherently safe from catastrophic backtracking, but this pattern has been additionally verified for correctness. RegexVault audits patterns against known backtracking attack vectors, ensuring you have the necessary context before using this regex in a high-stakes production environment.
Common Pitfalls
Zone IDs (the %eth0 part) are OS-specific and not part of the RFC 4007 standard address format — strip them before storage or comparison.
Technical Notes
The fe80::/10 block means the first 10 bits are 1111111010, which covers fe80 through febf. The [89AaBb] in position 3 covers the valid second-nibble range for this prefix.
Have a pattern that belongs in the vault?
Submit it for review — community-verified patterns get credited to your GitHub handle. Free submissions join the queue. Priority review available for $15.
Submit a Pattern