//g
  • 100% Free
  • No Sign-Up
  • No Credit Card
  • No Free Trial
  • No Pro Tier
  • No Watermarks

Nothing is uploaded. Just open it and start.

IPv4 Address Regex

Four numbers from 0 to 255 separated by dots, without leading zeros.

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

Piece by piece

  1. ^the start of the text
  2. (?:a group (not captured)
  3. (?:a group (not captured)
  4. 25the text “25”
  5. [0-5]one of 0–5
  6. |or
  7. 2the character “2”
  8. [0-4]one of 0–4
  9. \da digit (0–9)
  10. |or
  11. 1the character “1”
  12. \da digit (0–9)
  13. \da digit (0–9)
  14. |or
  15. [1-9]?one of 1–9, repeated optionally (0 or 1 time), as many as possible
  16. \da digit (0–9)
  17. )end of the group
  18. \.the character “.”
  19. ){3}end of the group, repeated exactly 3 times, as many as possible
  20. (?:a group (not captured)
  21. 25the text “25”
  22. [0-5]one of 0–5
  23. |or
  24. 2the character “2”
  25. [0-4]one of 0–4
  26. \da digit (0–9)
  27. |or
  28. 1the character “1”
  29. \da digit (0–9)
  30. \da digit (0–9)
  31. |or
  32. [1-9]?one of 1–9, repeated optionally (0 or 1 time), as many as possible
  33. \da digit (0–9)
  34. )end of the group
  35. $the end of the text

Examples

TextResult
192.168.1.1Matches
0.0.0.0Matches
255.255.255.255Matches
10.0.0.254Matches
256.1.1.1Doesn't match
1.2.3Doesn't match
01.2.3.4Doesn't match
1.2.3.4.5Doesn't match
  • It doesn't accept CIDR suffixes such as /24 or IPv6 addresses.

Other common patterns

Test any regular expression →

Frequently asked questions

How do I use this ipv4 address regex in JavaScript?
Write it as /^(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)$/ and call re.test(text). It is anchored with ^ and $, so it checks the whole text; remove them to find it inside longer text (and add the g flag to find every one). The Code view writes it out for Python, Go and PHP too.
Is it a complete validator?
No regex is the whole story. It doesn't accept CIDR suffixes such as /24 or IPv6 addresses.
Can I try it on my own text?
Yes. The tester above already holds the examples; paste your own text over them and every match is highlighted as you type. Nothing is uploaded.

Spotted a bug or have a suggestion?

Found something broken, have an idea, or just want to say thanks about any of our tools? Every message reaches a real person.