From 8ee1d17c5dae8a1558759774fd41faea46a86dc1 Mon Sep 17 00:00:00 2001 From: Moul <moul@moul.re> Date: Mon, 14 Jun 2021 18:10:04 +0200 Subject: [PATCH] [enh] #170: Define more compact ipv4 regex composed out of common part --- duniterpy/constants.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/duniterpy/constants.py b/duniterpy/constants.py index 28291184..0612ddad 100644 --- a/duniterpy/constants.py +++ b/duniterpy/constants.py @@ -28,10 +28,9 @@ CONDITIONS_REGEX = ( pubkey_regex=PUBKEY_REGEX, hash_regex=HASH_REGEX ) ) -IPV4_REGEX = ( - "(?:(?:[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])" -) +# https://stackoverflow.com/a/17871737 +IPV4SEG = "(?:25[0-5]|(?:2[0-4]|1?\\d)?\\d)" +IPV4_REGEX = f"(?:{IPV4SEG}\\.){{3}}{IPV4SEG}" 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," -- GitLab