Regex IP Address Patrones Referencia
Referencia para IPv4, IPv6, y CIDR notation validation regex patrones.
IPv4 Patterns
Simple IPv4: ^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$ (allows invalid octets like 999). Strict IPv4: ^(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\. (repeat 4 times)$. CIDR: append /([0-9]|[12]?\d|3[0-2]) for /0 to /32. Private ranges: 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16. Loopback: 127.0.0.0/8. For strict validation, parse octets and check 0-255 range programmatically. The strict regex is complex but accurate.
- simple
- 4 dot-separated octets
- strict
- 0-255 per octet
- CIDR
- IP/prefix
allows 999 complex /0 to /32 IPv6 Patterns
IPv6 is complex due to compression (::) and mixed notation. Simple: ^[0-9a-fA-F:]+$ (very permissive). Full: ^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$ (no compression). With :: compression requires careful handling of the double colon. IPv4-mapped: ::ffff:IPv4. Link-local: fe80::/10. ULA: fc00::/7. For robust IPv6 validation, use a parser, not regex. Regex can extract potential IPv6 from text but should not be the sole validator. Combine with programmatic range checks.
- full
- 8 hextets, no ::
- compressed
- With ::
- mixed
- IPv4-mapped
no compression complex regex ::ffff:a.b.c.d