I'm trying to use Lua pattern matching in a Wikipedia module to locate instances of Mediawiki parameter syntax (e.g. {{{parameter1-a|defaultValue}}}
or {{{parameter1-a|{{{alias1-a|defaultValue}}}}}}
) so they can be converted into Lua-compatible argument syntax. (Yes, I am fully aware that using pattern matching for this is an unforgivable crime against humanity, but whatever.)
So far, I have this relatively simple pattern, which works fine for the most part:
"{{{([^{}<>|]+)(|?([^{}|]*))}}}"
(Regex equivalent [hopefully], if you want to test on regex101: /{{{([^{}<>|]+)(?:\|([^{}|]+)?)?}}}/g
)
However, this can't properly match anything in the "default" part that itself contains curly braces, so I can't include aliases for the parameter or template wikitext in the default. More specifically:
- The unmodified regex will, if given something like
{{{parameter|{{{alias|default}}}}}}
, just match/capture {{{parameter|{{{alias
|default
}}}}}}. - Removing the curly brace restriction (
"{{{([^{}<>|]+)(|?([^{}|]*))}}}"
) will succeed with{{{parameter|{{{alias}}}}}}
, yielding {{{parameter
|{{{alias}}}
}}} as intended, but with a default on the alias it'll give {{{parameter|{{{alias
|default}}}
}}} - Just matching everything (
"{{{([^{}<>|]+)(|?(.*))}}}"
) works perfectly with one parameter, but with two it'll "spill" if the first has a default:{{{parameter1|default}}} {{{parameter2}}}
will yield {{{parameter1
|default}}} {{{parameter2
}}}
How do I solve this?