Regex for IPv4 Address Validation

A naive IPv4 pattern like \d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} matches 999.999.999.999, which isn't a valid address — each octet actually has to be 0–255. This pattern's alternation (25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?) enforces the real range per octet.

This is IPv4 only. It won't match IPv6 addresses at all — those need an entirely different pattern.