Open Gonzalo933 opened 1 year ago
From the documentation:
matches can be used to further restrict the nodes, either as a function (taking a single Node and returning a boolean) or a regular expression (matched against the node’s string representation with re.search()). If matches is a regex, the flags passed to re.search() are re.IGNORECASE, re.DOTALL, and re.UNICODE, but custom flags can be specified by passing flags.
So your matches="Infobox medical condition (new)"
, taken as a regex, does not match the final \n
in the template name. Note that this is different from the Wikicode.matches method. To filter with the latter, use:
mwparserfromhell.parse(text).filter_templates(matches=lambda template: template.name.matches("Infobox medical condition (new)"))
When filtering templates, if the template name has a linebreak there is no way of filtering it with the
matches
param.For example, given this text from the source: https://en.wikipedia.org/wiki/Cholera
Some templates are correctly found:
but when trying to match the "Infobox medical condition (new)" one the filter does not work.