Skip to main content
Regexflux

IPv4 Address

intermediate

Matches valid IPv4 addresses like 192.168.1.1.

ipipv4networkvalidation

Pattern

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

Try It

0 of 8 strings matched

Explanation

Matches four octets separated by dots. Each octet is validated to be 0-255 using alternation: 250-255, 200-249, or 0-199. Word boundaries prevent partial matches.

Test Strings

Matching

  • 192.168.1.1
  • 10.0.0.0
  • 255.255.255.255
  • 0.0.0.0

Non-matching

  • 256.1.1.1
  • 192.168.1
  • abc.def.ghi.jkl
  • 999.999.999.999

Language Compatibility

LanguageSupport
JSFull support
PYTHONFull support
JAVAFull support
PHPFull support
GOLimited support (ASCII-only word boundaries)

Code Snippets

const regex = /\b(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\b/g;
const text = "your text here";
const matches = text.match(regex);
console.log(matches);

Common Variations

With port

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

Matches IPv4 with port number

Related Patterns