| f | import re | f | import re |
| | | |
| t | def ipv6match(text: str): | t | def ipv6match(s: str): |
| s = '(?:[0-9A-Fa-f]{1,4})' | | h16 = '[0-9A-Fa-f]{1,4}' |
| ipv6 = f'^(?:(?:{s}:){{7}}{s}|(?:{s}:){{1,7}}:|:(?:{s}:){{1,7}}|(?:{ | | MAINREG = f'^(?:(?:{h16}:){{7}}{h16}|(?:{h16}:){{1,7}}:|(?:{h16}:){{ |
| s}:){{1,6}}:{s}|(?:{s}:){{1,5}}(?::{s}){{1,2}}|(?:{s}:){{1,4}}(?::{s}){{ | | 1,6}}:{h16}|(?:{h16}:){{1,5}}(?::{h16}){{1,2}}|(?:{h16}:){{1,4}}(?::{h16 |
| 1,3}}|(?:{s}:){{1,3}}(?::{s}){{1,4}}|(?:{s}:){{1,2}}(?::{s}){{1,5}}|{s}: | | }){{1,3}}|(?:{h16}:){{1,3}}(?::{h16}){{1,4}}|(?:{h16}:){{1,2}}(?::{h16}) |
| (?::{s}){{1,6}}|(?::(?::[0-9A-Fa-f]{{1,4}}){{1,7}})|::)$' | | {{1,5}}|{h16}:(?:(?::{h16}){{1,6}})|:(?:(?::{h16}){{1,7}}|:))$' |
| return re.match(ipv6, text) | | return re.match(MAINREG, s) |