Skip to main content
CalcHive

Regex for IPv4 Address

Matches valid IPv4 addresses (0.0.0.0 to 255.255.255.255) with proper octet range validation.

Pattern

/^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/

Pattern Breakdown

TokenExplanation
^Start of string
(?:25[0-5]|2[0-4]\d|[01]?\d\d?)Octet: 0-255
\.Literal dot separator
{3}Repeat first three octets with dots
(?:25[0-5]|2[0-4]\d|[01]?\d\d?)Fourth octet: 0-255
$End of string

Test Examples

InputMatch?
192.168.1.1Match
0.0.0.0Match
255.255.255.255Match
256.1.1.1No match
192.168.1No match

Common Use Cases

  • Network configuration validation
  • Firewall rule input
  • Log parsing
  • Server configuration

Variations

\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b

Simpler (no range validation)

Want to test this pattern with your own data?

Open the Regex Tester