@@ -35,6 +35,7 @@ class Rule(Serializable):
3535 """
3636
3737 __FIELDS_REGEX = re .compile (r"{(.+?)}" )
38+ __EXTRACT_FIELDS_REGEX = re .compile (r"(\{.+?(?::.+?)?\})" )
3839 __PATTERN_SEPARATORS_REGEX = re .compile (
3940 r"(}[_\-\.:\|/\\]{|[_\-\.:\|/\\]{|}[_\-\.:\|/\\])"
4041 )
@@ -134,7 +135,11 @@ def parse(self, name: AnyStr) -> Union[Dict, None]:
134135 dict: A dictionary with keys as tokens and values as given name parts.
135136 e.g.: {'side':'C', 'part':'helmet', 'number': 1, 'type':'MSH'}
136137 """
137- expected_separators = self .__PATTERN_SEPARATORS_REGEX .findall (self ._pattern )
138+ extract_tokens = self .__EXTRACT_FIELDS_REGEX .findall (self ._pattern )
139+ pattern_wout_tokens = self ._pattern
140+ for each in extract_tokens :
141+ pattern_wout_tokens = pattern_wout_tokens .replace (each , "XYZ" )
142+ expected_separators = self .__SEPARATORS_REGEX .findall (pattern_wout_tokens )
138143 if len (expected_separators ) <= 0 :
139144 logger .warning (
140145 f"No separators used for rule '{ self .name } ', parsing is not possible."
@@ -186,7 +191,11 @@ def validate(self, name: AnyStr, strict: bool = False, **validate_values) -> boo
186191 Returns:
187192 bool: True if name matches the rule pattern, False otherwise.
188193 """
189- expected_separators = self .__PATTERN_SEPARATORS_REGEX .findall (self ._pattern )
194+ extract_tokens = self .__EXTRACT_FIELDS_REGEX .findall (self ._pattern )
195+ pattern_wout_tokens = self ._pattern
196+ for each in extract_tokens :
197+ pattern_wout_tokens = pattern_wout_tokens .replace (each , "XYZ" )
198+ expected_separators = self .__SEPARATORS_REGEX .findall (pattern_wout_tokens )
190199 if len (expected_separators ) <= 0 :
191200 logger .warning (
192201 f"No separators used for rule '{ self .name } ', parsing is not possible."
0 commit comments