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

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find IPv6 addresses including compressed and IPv4-embedded variants (RFC 2373)
Expression
(::|(([a-fA-F0-9]{1,4}):){7}(([a-fA-F0-9]{1,4}))|(:(:([a-fA-F0-9]{1,4})){1,6})|((([a-fA-F0-9]{1,4}):){1,6}:)|((([a-fA-F0-9]{1,4}):)(:([a-fA-F0-9]{1,4})){1,6})|((([a-fA-F0-9]{1,4}):){2}(:([a-fA-F0-9]{1,4})){1,5})|((([a-fA-F0-9]{1,4}):){3}(:([a-fA-F0-9]{1,4})){1,4})|((([a-fA-F0-9]{1,4}):){4}(:([a-fA-F0-9]{1,4})){1,3})|((([a-fA-F0-9]{1,4}):){5}(:([a-fA-F0-9]{1,4})){1,2}))
Description
This RE recognizes IPv6 addresses for all the representations described by RFC 2373: 1) extended format (with both upper and lowercase HEX) 2) compressed format (eg 2001::6:a) 3) IPv4-embedded format (eg ::ffff:1.2.3.4) limited to addresses of the traditional dual-stack configuration Resulting from observation of real-world implementations, case 2) is extended to allow "::" for one 0-group alone. Although the RFC is clear on "::" being for "multiple groups of 16-bits of zeros" only, some tools like "dig" for the mac produce those values. The RE is simple and quite elegant; it has been tested on over 300 IPv6 addresses collected by dig-ing IPv6-enabled domains; it is used in sshguard's log parser, see http://www.sshguard.net .
Matches
2001:470:b0b4:1:280:c6ff:fef2:9410 | 2001:868:100::3 | 2001:888:144a::a441:888:1002 | ::1 | a:b:: | ::FFFF:1.2.3.4
Non-Matches
1:2:3:4:5:6:7:8:9 | a::b::c | x:x:x:x:x:x:x:x
Author Rating: Not yet rated. mij
Source www.sshguard.net
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: Not matched.. need to get clarified
Name: Amarnath
Date: 12/24/2013 1:54:21 AM
Comment:
::FFFF:1.2.3.4 is not matched...


Title: Flawed
Name: Aeron
Date: 6/17/2010 8:55:05 AM
Comment:
Does not accept: 1111:2222:3333:4444:5555:6666:7777:: 1111:2222:3333:4444:5555:6666::8888 ::2222:3333:4444:5555:6666:7777:8888 1111:2222:3333:4444:5555:6666:123.123.123.123 1111:2222:3333:4444:5555::123.123.123.123 1111:2222:3333:4444::123.123.123.123 1111:2222:3333::123.123.123.123 1111:2222::123.123.123.123 1111::123.123.123.123 1111:2222:3333:4444::6666:123.123.123.123 1111:2222:3333::6666:123.123.123.123 1111:2222::6666:123.123.123.123 1111::6666:123.123.123.123 ::6666:123.123.123.123 1111:2222:3333::5555:6666:123.123.123.123 1111:2222::5555:6666:123.123.123.123 1111::5555:6666:123.123.123.123 ::5555:6666:123.123.123.123 1111:2222::4444:5555:6666:123.123.123.123 1111::4444:5555:6666:123.123.123.123 ::4444:5555:6666:123.123.123.123 1111::3333:4444:5555:6666:123.123.123.123 ::2222:3333:4444:5555:6666:123.123.123.123


Title: Sorry
Name: Aeron
Date: 6/17/2010 8:45:44 AM
Comment:
Ignore previous comment, mixed up regex.


Title: Flawed
Name: Aeron
Date: 6/17/2010 8:42:30 AM
Comment:
::2222:3333:4444:5555:7777:8888:: is accepted


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