From cb1772a234c011af7b161408afc892ca091bb4ac Mon Sep 17 00:00:00 2001 From: Lavissa Date: Sat, 11 May 2024 00:47:38 +0200 Subject: [PATCH] Permit special chars in literals (#3) Adds support for using the following special characters in literal groups: . : \ / - _ --- ipn_generator/generator.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ipn_generator/generator.py b/ipn_generator/generator.py index d50d1dc..353c9af 100644 --- a/ipn_generator/generator.py +++ b/ipn_generator/generator.py @@ -9,6 +9,8 @@ logger = logging.getLogger("inventree") +PERMITTED_SPECIAL_LITERALS = "\-.:/\\" + def validate_pattern(pattern): """Validates pattern groups""" @@ -118,7 +120,7 @@ def construct_regex(self, disable_groups=False): regex = "^" m = re.findall( - r"(\{\d+\+?\})|(\([\w\(\)]+\))|(\[(?:\w+|\w-\w)+\])", + r"(\{\d+\+?\})|(\([\w\(\)\-.:/\\]+\))|(\[(?:\w+|\w-\w)+\])", self.get_setting("PATTERN"), ) @@ -248,7 +250,7 @@ def increment_ipn(self, exp, latest): def construct_first_ipn(self): """No IPNs matching the pattern were found. Constructing the first IPN.""" m = re.findall( - r"(\{\d+\+?\})|(\([\w\(\)]+\))|(\[(?:\w+|(?:\w-\w)+)\])", + r"(\{\d+\+?\})|(\([\w\(\)\-.:/\\]+\))|(\[(?:\w+|(?:\w-\w)+)\])", self.get_setting("PATTERN"), )