DD
DevDash

Regex for IPv6 Address

Regex Pattern

^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$

Basic IPv6 address (8 groups of 4 hex digits)

Quick Answer

The regex pattern for ipv6 address is `^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$`. Basic IPv6 address (8 groups of 4 hex digits). This works in JavaScript, Python, Ruby, PHP, Java, and most regex engines that support PCRE syntax.

Test Examples

InputResult
2001:0db8:85a3:0000:0000:8a2e:0370:7334✓ Matches
fe80:0000:0000:0000:0204:61ff:fe9d:f156✓ Matches
2001:db8::8a2e:370:7334✗ No match
not-an-ipv6✗ No match
192.168.1.1✗ No match

Code Examples

javascript

const regex = /^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$/;
const isValid = regex.test(value);

python

import re
pattern = r'^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$'
if re.match(pattern, value):
    print("valid")

ruby

pattern = /^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$/
if value =~ pattern
  puts "valid"
end

php

if (preg_match('/^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$/', $value)) {
    echo "valid";
}

java

String pattern = "^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$";
boolean isValid = value.matches(pattern);

Frequently Asked Questions

Related Regex Patterns

Want API access + no ads? Pro coming soon.