| Title | Test
                    Find
                    
                    IPv6 address | 
            
                | Expression | ^([0-9a-fA-F]{4}|0)(\:([0-9a-fA-F]{4}|0)){7}$ | 
            
                | Description | IPv6 address (128 bit). Matches hexadecimal patterns and single 0 in the address. | 
            
                | Matches | 3e4f:123f:c12a:5566:888e:9975:aaff:2344 | 3e4f:123f:c12a:0:0:0:0:2344 | 0000:0000:0000:0000:0000:000 | 
            
                | Non-Matches | 3e4f:123f:c12a:5566:888e:9975:aafg:2344 | 3e4f:123f:c12a:0:0:0:1:2344 | 0000:0000:0000:0000:0000:000 | 
            
                | Author | Rating:
                        
Not yet rated.
                    Dean Dal Bozzo | 
            
                | Source |  | 
            
              | Your Rating |  | 
        
    
 
    
    
     
        
                
	                Title: Many other regular expressions for Perl, Java, Ruby, Javascript
	                Name: Rich Brown
	                Date: 2/25/2010 11:10:49 PM
	                Comment: 
We've found a number of other RE's that do the trick. Check out http://forums.dartware.com/viewtopic.php?t=452
There's a perl script there that has over 200 test cases as well.
                
                
            
                
	                Title: Many other regular expressions for Perl, Java, Ruby, Javascript
	                Name: Rich Brown
	                Date: 2/25/2010 11:09:55 PM
	                Comment: 
We've found a number of other RE's that do the trick. Check out http://forums.dartware.com/viewtopic.php?t=452
There's a perl script there that has over 200 test cases as well.
                
                
            
                
	                Title: Incomplete
	                Name: Schwern
	                Date: 11/27/2009 8:00:43 PM
	                Comment: 
This regex is incomplete.  It misses valid IPv6 addresses such as ::ffff:c000:280 fe80:: and 2001:db8:a::123
                
                
            
                
	                Title: Not working for all IP addresses
	                Name: john
	                Date: 10/22/2008 5:31:42 AM
	                Comment: 
if :: are used it wont work
                
                
            
                
	                Title: Not working with Java's Pattern class
	                Name: Jeybas
	                Date: 11/14/2007 12:08:43 PM
	                Comment: 
Do any of these regular expressions work with Java's Pattern class. I ca'nt seem to get any working. 
                
                
            
                
	                Title: A couple of improvements
	                Name: Andrew McMillan
	                Date: 4/17/2007 9:49:01 PM
	                Comment: 
As the previous commenter points out, each of the quads may be shorter than 4 characters, and the missing digits are assumed to be zero.  So a wider validation would be:
^[0-9a-fA-F]{1,4}(\:[0-9a-fA-F]{1,4}){7}$
Of course this still does not address issues of the possible shortening of IPv6 addresses where a long repeat of '0:' may be replaced with '::' ...
For my own case I have implemented a "canonicalise" function which converts the '::' back into a suitable number of '0:' before validating against the above regex.
Here is some (very crude, bad) perl to canonicalise them:
sub canonicalise_ipv6_address {
my $v6_in = shift;
  return $v6_in if ( $v6_in !~ /\:\:/ );
  my $colons = $v6_in;
  $colons =~ s/[^:]//g;
  my $replace = ':';
  for (my $i=length($colons); $i < 8; $i++ ) {
    $replace .= '0:';
  }
  my $replaced = $v6_in;
  $replaced =~ s/\:\:/$replace/;
  $replaced =~ s/^\:/0\:/;
  $replaced =~ s/\:$/\:0/;
  return $replaced;
}
That's laborious, I'm sure.  No doubt a perl guru could write it all in one magic regex.  If you are such a person then feel free to do so in a comment below :-)
Thanks,
Andrew McMillan.
                
                
            
                
	                Title: not working for all
	                Name: Muhittin
	                Date: 10/4/2005 7:05:59 AM
	                Comment: 
It doesn't match:
3e4f:23f:c12a:5566:888e:9975:aaff:2344
Note the second word, zero padding is OK to be removed.