REGEXVAULTv2.0
Web & Network/IPv6
Verified Safe

IPv6 Link-Local Address Regex for Python

/^[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 Python. A rigorously tested regex reduces debugging time and protects your application from edge-case failures. The snippet below is ready to drop into your Python project — whether you're validating in a Django view, a FastAPI endpoint, or a standalone data processing script.

Python Implementation

Python
# IPv6 Link-Local Address
# ReDoS-safe | RegexVault — Web & Network > IPv6

import re

ipv6_linklocal_address_pattern = re.compile(r'^[Ff][Ee][89AaBb][0-9a-fA-F](?::[0-9a-fA-F]{0,4}){0,7}(?:%[a-zA-Z0-9_.-]{1,20})?$')

def validate_ipv6_linklocal_address(value: str) -> bool:
    return bool(ipv6_linklocal_address_pattern.fullmatch(value))

# Example
print(validate_ipv6_linklocal_address("fe80::1"))  # True

Test Cases

Matches (Valid)
Rejects (Invalid)
fe80::1fc00::1
fe80::1%eth02001:db8::1
fe80::a1b2:c3d4:e5f6:0001::1
fe80::1%lo0fe80::1%
FE80::1%en0fe70::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 Python developers because particularly important in Python web servers where CPU-bound regex operations can stall concurrent request handling. 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