Skip to content
Snippets Groups Projects
Commit 5722ad54 authored by Moul's avatar Moul
Browse files

[enh] #170: Define more compact ipv6 regex

composed out of common part
parent 8ee1d17c
No related branches found
No related tags found
2 merge requests!157v1.0.0rc0: merge dev into master,!145#170: Endpoints' regex improvement
......@@ -31,23 +31,14 @@ CONDITIONS_REGEX = (
# https://stackoverflow.com/a/17871737
IPV4SEG = "(?:25[0-5]|(?:2[0-4]|1?\\d)?\\d)"
IPV4_REGEX = f"(?:{IPV4SEG}\\.){{3}}{IPV4SEG}"
IPV6SEG = "[0-9a-fA-F]{1,4}"
IPV6_REGEX = (
"(?:(?:[0-9A-Fa-f]{1,4}:){6}(?:[0-9A-Fa-f]{1,4}:[0-9A-Fa-f]{1,4}|(?:(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2["
"0-4][0-9]|25[0-5])\\.){3}(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))|::(?:[0-9A-Fa-f]{1,"
"4}:){5}(?:[0-9A-Fa-f]{1,4}:[0-9A-Fa-f]{1,4}|(?:(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){"
"3}(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))|(?:[0-9A-Fa-f]{1,4})?::(?:[0-9A-Fa-f]{1,"
"4}:){4}(?:[0-9A-Fa-f]{1,4}:[0-9A-Fa-f]{1,4}|(?:(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){"
"3}(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))|(?:[0-9A-Fa-f]{1,4}:[0-9A-Fa-f]{1,"
"4})?::(?:[0-9A-Fa-f]{1,4}:){3}(?:[0-9A-Fa-f]{1,4}:[0-9A-Fa-f]{1,4}|(?:(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2["
"0-4][0-9]|25[0-5])\\.){3}(?:[0-9]|[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(?::{IPV6SEG}){{1,5}}|"
f"{IPV6SEG}:(?:(?::{IPV6SEG}){{1,6}})|:(?:(?::{IPV6SEG}){{1,7}}|:)|"
f"fe80:(?::{IPV6SEG}){{0,4}}%[0-9a-zA-Z]+|::(?:ffff(?::0{{1,4}})?:)?{IPV4_REGEX}|"
f"(?:{IPV6SEG}:){{1,4}}:{IPV4_REGEX}"
)
HOST_REGEX = "[a-z0-9-_.]*(?:.[a-zA-Z])?"
# https://stackoverflow.com/a/12968117
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment