Skip to content
uencoder

Regex IP Address Patterns Reference

Reference for IPv4, IPv6, and CIDR notation validation regex patterns.

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
allows 999
strict
0-255 per octet
complex
CIDR
IP/prefix
/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 ::
no compression
compressed
With ::
complex regex
mixed
IPv4-mapped
::ffff:a.b.c.d

Related tools

References