Skip to main content
Network & Web · In-Browser Regular Expression Lab

IPv4 Regex — Validate 0-255 Decimal Octets with CIDR Support

Strictly validates IPv4 addresses ensuring each octet is within the valid 0 to 255 numerical range.

Flags:
//none
Match Found
Load Sample:
Match Inspection & Details1 match
Match #1:192.168.1.1

Test Samples Verification Matrix

Expected Valid Samples (Should Match)

192.168.1.1 Pass
10.0.0.254 Pass
127.0.0.1 Pass
255.255.255.0 Pass

Expected Invalid Samples (Must Reject)

256.1.1.1 Rejected (Pass)
192.168.1 Rejected (Pass)
192.168.1.1.1 Rejected (Pass)
1.2.3.999 Rejected (Pass)
Code Implementation Generator
// JavaScript / TypeScript (ES6+)
const pattern = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
const text = "192.168.1.1";

const isMatch = pattern.test(text);
console.log("Is Match:", isMatch);

if (isMatch) {
  const matches = text.match(pattern);
  console.log("Matches:", matches);
}

Regular Expression Token Breakdown

Checks four dot-separated octets ensuring numbers never exceed 255. Each component of the regular expression serves a distinct syntactical purpose as mapped below:

Token PatternName / ComponentFunction & Rule
25[0-5]Range 250-255Matches 250 to 255.
2[0-4][0-9]Range 200-249Matches 200 to 249.
[01]?[0-9][0-9]?Range 0-199Matches 0 to 199.
\.Dot delimiterMatches period separating octets.
{3}Repeat 3 timesRepeats octet and dot for the first 3 groups.

Frequently Asked Questions

How to add CIDR subnet support?
Append `(?:\/(?:[0-9]|[1-2][0-9]|3[0-2]))?$` to allow `/24`, `/16`, etc.
Browse All 40 Patterns