Note that there are some explanatory texts on larger screens.

plurals
  1. PORegex to match MediaWiki template and its parameters
    text
    copied!<p>I'm writing a simple Javascript to add a specific parameter to a specific template in article that is currently being edited.</p> <p>Wikipedia Templates are structured in the following format:</p> <pre><code> {{Template name|unnamed parameter|named parameter=some value|another parameter=[[target article|article name]]|parameter={{another template|another tamplate's parameter}}}} </code></pre> <p>One template can also be over more lines, for example:</p> <pre><code>{{Template |name=John |surname=Smith |pob=[[London|London, UK]] }} </code></pre> <p>For further reference, please have a look at <a href="http://en.wikipedia.org/wiki/Help:Template" rel="nofollow">http://en.wikipedia.org/wiki/Help:Template</a></p> <p>So firstly I'd like to match the entire template. I came over partial solution, that is:</p> <pre><code>document.editform.wpTextbox1.value.match(/\{\{template name((.|\n)*?)\}\}$/gmis) </code></pre> <p>However the problem is that it only matches text from the initial brackets till the closing brackets of the first nested template (first example). </p> <p>In addition I'd like to fetch its parameters in an array form. So for the result, I'd like to get an array with parameters in specific order. Array( value of paramter pob, value of paramter name, value of parameter surname, value of parameter pod (in this case empty, because it was unset) )</p> <p>I'd use that to clean the unstandardised formatting in some articles and add some new parameters. </p> <p>Thank you!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload