Regex Pattern

IPv4 Address Regex

By Samrat•Last updated: Nov 2026
Regex 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]?)$

Quick answer

This regex validates IPv4 addresses. It ensures that each of the four numbers is between 0 and 255, separated by dots.

🛠️ Fix it right here with AI Regex Generator

Need to modify this pattern or generate a new one? Edit the regex below and let our AI help.

AI suggestions can be wrong. Review and test before applying.

Live Regex Tester

Type a string below to see if it matches this pattern.

How it works

The pattern repeats 4 times, separated by dots. (?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?) matches numbers from 250-255, 200-249, and 0-199 respectively.

Code Examples

✅ Correct Usage

// JavaScript
const ipv4Regex = /^(?:(?: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]?)$/;
console.log(ipv4Regex.test("192.168.1.1")); // true
console.log(ipv4Regex.test("999.1.1.1")); // false

❌ What NOT to do

// BAD: Matches 999.999.999.999
const badRegex = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;

Frequently asked questions

Does this validate IPv6?

No. IPv6 uses hexadecimal and colons (e.g., 2001:0db8:85a3::8a2e:0370:7334). It requires a completely different regex.

Related Search Terms

ipv4 regexip address regexregex for ipvalidate ipv4

Related Regex Patterns

Need a custom regex pattern?

Use the free to describe what you need in plain English.

Want an AI with memory for your project?

MonsterX AI remembers your codebase across chats.