IPv6 Link-Local Address Regex for Java
/^[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 Java. A rigorously tested regex reduces debugging time and protects your application from edge-case failures. The snippet below is ready to drop into your Java project — whether you're validating in a Spring Boot controller, a Jakarta EE service, or a standalone utility class.
Java Implementation
// IPv6 Link-Local Address
// ReDoS-safe | RegexVault — Web & Network > IPv6
import java.util.regex.Pattern;
public class Ipv6LinklocalAddressValidator {
private static final Pattern PATTERN =
Pattern.compile("^[Ff][Ee][89AaBb][0-9a-fA-F](?::[0-9a-fA-F]{0,4}){0,7}(?:%[a-zA-Z0-9_.-]{1,20})?$");
public static boolean validate(String input) {
return PATTERN.matcher(input).matches();
}
// Example
public static void main(String[] args) {
System.out.println(validate("fe80::1")); // true
}
}Test 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 Java developers because critical in Java applications since the JVM regex engine uses backtracking and is susceptible to ReDoS without careful pattern design. 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