- The first Regular Expression Library on the Web!

Please support RegExLib Sponsors


Regular Expression Details

Title Test Find Pattern Title
This matches an IP address, putting each number in its own group that can be retrieved by number. If you do not care about capturing the numbers, then you can make this shorter by putting everything after ^ until immediately after the first \. in a group ( ) with a {3} after it. Then put the number matching regex in once more. It only permits numbers in the range 0-255.
Matches | |
Non-Matches | |
Author Rating: The rating for this expression. Andrew Polshaw
Your Rating
Bad Good

Enter New Comment

Spammers suck - we apologize. Please enter the text shown below to enable your comment (not case sensitive - try as many times as you need to if the first ones are too hard):

Existing User Comments

Title: Your Shortened version is so good you should list it separately
Name: James Glenski
Date: 1/4/2018 6:42:57 PM
I like the shortened version. ^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])(\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])){3}$ Works like a champ.

Title: Thanks
Name: John
Date: 7/3/2010 7:12:39 PM
Thanks for the regex Andrew and thanks to eger for the updated copy (thanks 5 years later, hehe). :)

Title: updated version
Name: eger
Date: 5/6/2005 4:54:07 PM
I was having similar problems as sergeya suggested. so i went ahead and modified Andrews a bit to be more strict. This one will not allow 0 as the first octect, 0 in front of any octet number, or multiple 0's: ^([1-9]{1}\d{1}|[1-9]{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1}|[1-9]{1}\d{1}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1}|[1-9]{1}\d{1}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1}|[1-9]{1}\d{1}|1\d\d|2[0-4]\d|25[0-5])$

Title: prob with this regexp
Name: sergeya
Date: 6/10/2004 8:21:18 PM
allows - does not check for 0 in 2-digit groups

Title: Shortening?
Name: Ri
Date: 2/15/2004 3:53:45 AM
Could you be so kind as to give a snippet of this shortening you speak of in the description?

Copyright © 2001-2018, | ASP.NET Tutorials