| f | import re | f | import re |
| | | |
| def ipv6match(s): | | def ipv6match(s): |
| h16 = '[0-9A-Fa-f]{1,4}' | | h16 = '[0-9A-Fa-f]{1,4}' |
| ipv6_full = f'(?:{h16}:){{7}}{h16}' | | ipv6_full = f'(?:{h16}:){{7}}{h16}' |
| ipv6_7 = f'(?:{h16}:){{1,7}}:' | | ipv6_7 = f'(?:{h16}:){{1,7}}:' |
| ipv6_6 = f'(?:{h16}:){{1,6}}:{h16}' | | ipv6_6 = f'(?:{h16}:){{1,6}}:{h16}' |
| n | ipv6_52 = f'(?:{h16}:){{1,5}}(?::{h16}){{1,2}}' | n | ipv6_5 = f'(?:{h16}:){{1,5}}(?::{h16}){{1,2}}' |
| ipv6_43 = f'(?:{h16}:){{1,4}}(?::{h16}){{1,3}}' | | ipv6_4 = f'(?:{h16}:){{1,4}}(?::{h16}){{1,3}}' |
| ipv6_34 = f'(?:{h16}:){{1,3}}(?::{h16}){{1,4}}' | | ipv6_3 = f'(?:{h16}:){{1,3}}(?::{h16}){{1,4}}' |
| ipv6_25 = f'(?:{h16}:){{1,2}}(?::{h16}){{1,5}}' | | ipv6_2 = f'(?:{h16}:){{1,2}}(?::{h16}){{1,5}}' |
| ipv6_1 = f'{h16}:(?:(?::{h16}){{1,6}})' | | ipv6_1 = f'{h16}:(?:(?::{h16}){{1,6}})' |
| ipv6_0 = f':(?:(?::{h16}){{1,7}}|:)' | | ipv6_0 = f':(?:(?::{h16}){{1,7}}|:)' |
| t | ipv6_pattern = '^(' + '|'.join([ipv6_full, ipv6_7, ipv6_6, ipv6_52, | t | ipv6_pattern = '^(' + '|'.join([ipv6_full, ipv6_7, ipv6_6, ipv6_5, i |
| ipv6_43, ipv6_34, ipv6_25, ipv6_1, ipv6_0]) + ')$' | | pv6_4, ipv6_3, ipv6_2, ipv6_1, ipv6_0]) + ')$' |
| return re.match(ipv6_pattern, s) | | return re.match(ipv6_pattern, s) |