. , , . https://regex101.com/r/G2n0cO/1/. , :
(?:^|[^\$])\${(?:(?P<section>[a-zA-Z0-9\-_]+?)\:)??(?P<key>[a-zA-Z0-9\-_]+?)(?:\[(?P<index>[0-9]+?)\])??\}
I still had to add a check to remove the last short-lived character. at the end of the example below. For the story, I saved a few iterations that I have done since I posted this question:
pattern = r'(?:^|[^\$])\${(?:(?P<section>[a-zA-Z0-9\-_]+?)\:)??(?P<key>[a-zA-Z0-9\-_]+?)(?:\[(?P<index>[0-9]+?)\])??\}'
analyser = re.compile(pattern)
mo = analyser.search(value, 0)
log.debug(f'got match object: {mo}')
while not mo is None:
log.debug(f'in while loop, level={level}')
if level > MAX_LEVEL:
raise RecursionError(f"to many recursive call to _substiture_text() while processing '{value}'.")
else:
level +=1
start = mo.start()
end = mo.end()
if value[start] != '$':
start += 1
source
share