Add named capture groups

This commit is contained in:
Michal Kunc 2021-11-24 12:55:45 +01:00
parent 24a9683608
commit c03ebbf853
Signed by: michal
GPG Key ID: 4CA5FB6559E0BDF8

View File

@ -17,10 +17,10 @@ with open("./db_explorer/en.json") as f:
@app.template_filter('filter_vtt')
def filter_vtt(text):
compendium_re = re.compile(r"@Compendium\[([^\]]+)\]\{([^\}]+)\}")
compendium_re = re.compile(r"@Compendium\[(?P<ref>[^\]]+)\]\{(?P<value>[^\}]+)\}")
def compendium_return(m):
# TODO: Actually add links
return f"<a>{m.group(2)}</a>"
return f"<a>{m.group('value')}</a>"
macro_re = re.compile(r"\[\[\/\S*?r(?:oll)?\s(?:(?P<sdice>[^\{\] ]+)[^\{\]]*|(?:\{(?P<ldice>[^\}]+)\}\[[^\]]+\])?)\]\](?:\{(?P<alt>[^\}]+)\})?")
def macro_return(m):
if m.group('alt') is not None: