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

[enh] #170: Define more compact ipv6 regex

composed out of common part
parent dbed45f9
No related branches found
No related tags found
No related merge requests found
...@@ -31,23 +31,14 @@ CONDITIONS_REGEX = ( ...@@ -31,23 +31,14 @@ CONDITIONS_REGEX = (
# https://stackoverflow.com/a/17871737 # https://stackoverflow.com/a/17871737
IPV4SEG = "(?:25[0-5]|(?:2[0-4]|1?\\d)?\\d)" IPV4SEG = "(?:25[0-5]|(?:2[0-4]|1?\\d)?\\d)"
IPV4_REGEX = f"(?:{IPV4SEG}\\.){{3}}{IPV4SEG}" IPV4_REGEX = f"(?:{IPV4SEG}\\.){{3}}{IPV4SEG}"
IPV6SEG = "[0-9a-fA-F]{1,4}"
IPV6_REGEX = ( 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[" f"(?:{IPV6SEG}:){{7}}{IPV6SEG}|(?:{IPV6SEG}:){{1,7}}:|(?:{IPV6SEG}:){{1,6}}:{IPV6SEG}|"
"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," f"(?:{IPV6SEG}:){{1,5}}(?::{IPV6SEG}){{1,2}}|(?:{IPV6SEG}:){{1,4}}(?::{IPV6SEG}){{1,3}}|"
"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])\\.){" f"(?:{IPV6SEG}:){{1,3}}(?::{IPV6SEG}){{1,4}}|(?:{IPV6SEG}:){{1,2}}(?::{IPV6SEG}){{1,5}}|"
"3}(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))|(?:[0-9A-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:){,4}[0-9A-Fa-f]{1,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}:){,5}[0-9A-Fa-f]{1,4})?::[0-9A-Fa-f]{1,4}|(?:(?:[0-9A-Fa-f]{1,"
"4}:){,6}[0-9A-Fa-f]{1,4})?::)(?:%.+)?"
) )
HOST_REGEX = "[a-z0-9-_.]*(?:.[a-zA-Z])?" HOST_REGEX = "[a-z0-9-_.]*(?:.[a-zA-Z])?"
# https://stackoverflow.com/a/12968117 # 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