All that I need is to split the wiki template call to parameter parts. In the very basic scenario it is just splitting by |
so {{template|unnamed_parameter|param1=value1}}
would be split to {{template
, unnamed_parameter
, param1=value1
and }}
.
But things are complicating when the pipe character is used for other purposes like for wikilinks [[link|title]]
etc.
Any suggestions how to do this task in the easiest way? :)
Update: Sorry for possible misunderstanding but {{template|unnamed_parameter|param1=value1}}
is just an example. For more information about wiki templates you can look at the following resource: http://www.mediawiki.org/wiki/Help:Templates
regex that assumes your wiki template has always 3 parts:
update to exclude false match to template
{{template|[[link|name]]}}
it's a simple regex using reluctant quantifiers and escaping the "special" meaning of
{}|
using\
by including
\{\{ \}\}
to the regex you avoid matches on[[ ]]
pattern.Please look at this Q&A: How can I fix this wiki link parsing regular expression?
My answer (in Update section) there using
perl regex
is doing pretty much similar Wiki link parsing.Update:
Alright here is the perl regex for your case:
Q: are you sure you need
and
here before closing}}
otherwise just edit above regex:And now checking above solution against string
[[link|title]]