Python (re)

IPv6 Address in PY

Match full (non-compressed) IPv6 addresses written as eight colon-separated hextets.

Try it in the PY tester →

Pattern

regexPY
(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}   (flags: g)

Python (re) code

pyPython
import re

pattern = re.compile(r"(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}")
input_text = "2001:0db8:85a3:0000:0000:8a2e:0370:7334"
for m in pattern.finditer(input_text):
    print(m.group(0))

Stdlib `re` module — no third-party dependency. Works on Python 3.6+.

How the pattern works

Seven groups of 1–4 hex digits each followed by a colon, then a final hextet. Does not cover :: shorthand or IPv4-mapped addresses — use a more complex pattern if you need those forms.

Examples

Input

2001:0db8:85a3:0000:0000:8a2e:0370:7334

Matches

  • 2001:0db8:85a3:0000:0000:8a2e:0370:7334

Input

::1

No match

Same pattern, other engines

← Back to IPv6 Address overview (all engines)