RegExLib.com - The first Regular Expression Library on the Web!

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find IPV4 and IPV6 address
Expression
([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4}|(\d{1,3}\.){3}\d{1,3}
Description
Matches all IPV6 and IPV4 addresses. Doesn't limit IPV4 to just values of 255. Doesn't allow IPV6 compression.
Matches
0:123:af00:ffff:0C67:0:0:8787 | 0:0:0:0:0:0:0:1 | 0.0.0.1 | 999.999.999.999
Non-Matches
::1
Author Rating: The rating for this expression. John Wilkins
Source
Your Rating
Bad Good

Enter New Comment

Title

Name

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: Developer
Name: iPrincess
Date: 6/12/2012 12:44:14 PM
Comment:
Thanks John, I was very happy to find a regex that worked (for the most part). Any ideas on how to get it to accept ipv6 with dropped leading zeros?


Title: Addition
Name: Gerry
Date: 12/21/2007 6:15:57 PM
Comment:
sorry, last posting is terrible to read ... also doesn't match an address like 2001:0DB8:0000:0000:0202:B3FF:FE1E:8329 --> 2001:DB8::202:B3FF:FE1E:8329. The double colon can replace consecutive zeros and leading zeros can also be skipped. Makes it really difficult to find an good expression.


Title: Very basic regexp
Name: Gerry
Date: 12/21/2007 6:05:35 PM
Comment:
Doesn't match addresses like 2001:0db8::0370:7344 2001:0db8::0370:: 2001:0db8:85a3:08d3:1319:8a2e:100.22.44.55 2001:0db8::8a2e:100.22.44.55


Copyright © 2001-2025, RegexAdvice.com | ASP.NET Tutorials