This is a question about a regex, and a corollary about the philosophy of recipe parameters.<div><br></div><div>I'm trying to write a directive recipe (see excerpt below)[<a href="http://khandallah.wellington.net.nz/pmwiki/pmwiki.php/Main/WikiSandbox">1</a>]</div>

<div>It seems to me that it makes sense to be relatively strict about the syntax for the directive.</div><div><br></div><div>It more or less get the parsing of the parameters correct, except for the backreference of the height|width parameters, where I did not want order to be important</div>

<div>(in fact other than the first ll | topo50 parameter I'd rather the order was not important).</div><div><br></div><div>Q: For height|width, when both are supplied I only see one (the last) returned as a backreference, is this because where there are multiple matches for a back reference only the last is returned?</div>

<div>(I haven't been able to locate any documentation about this).</div><div><br></div><div><br></div><div>In looking for an exemplar recipe I observe that</div><div><div><font face="courier new, monospace">Markup('exemplar', 'directive',</font></div>

<div><font face="courier new, monospace">  '/\\(:exemplar\s*(.*?)\s*:\\)/ei',</font></div><div><font face="courier new, monospace">  "FmtExemplar(PSS('$1')");</font></div></div><div>most directives accept anything within their scope, then use </div>

<div><font face="courier new, monospace">$arg = ParseArgs($args);</font></div><div><br></div><div>Then the arguments defined are processed, and any unexpected arguments are disregarded.</div><div><br></div><div>So my corollary question is:</div>

<div>Is this good practice, or just expedient, given the difficulty (as I perceive it) of defining a parameter list in regex?</div><div><br></div><div>tia</div><div><br></div><div>Simon</div><div><br></div><div><br></div>

<div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><div><font face="courier new, monospace" size="1">## Add a custom markup </font></div><div><font face="courier new, monospace" size="1"># (:nztopo ll=-41.293722,174.871482 :)</font></div>

<div><font face="courier new, monospace" size="1"># (:nztopo topo50=BP33912708,BP33876687 height=300 width=400 pin=1:)</font></div><div><font face="courier new, monospace" size="1"># arguments are</font></div><div><font face="courier new, monospace" size="1">#  ll= or topo50= -- latitude,longitude or topo50 map grid coordinates</font></div>

<div><font face="courier new, monospace" size="1">#  height= -- image height in pixels</font></div><div><font face="courier new, monospace" size="1">#  width= -- image width in pixels</font></div><div><font face="courier new, monospace" size="1">#  pin= -- show pin</font></div>

<div><font face="courier new, monospace" size="1">Markup( 'NZTopo', </font></div><div><font face="courier new, monospace" size="1">  'directives', "/\\(:nztopo ((?:ll=[-+]?\d{1,2}[.]\d+[,][-+]?[1]?\d{1,2}[.]\d+)|(?:topo50=[ABC][A-Z][0-4]\d{7}[,][ABC][A-Z][0-4]\d{7}))\s*((?:height|width)=\d+\s*){0,2}(pin=[01])?\s*:\\)/ei", </font></div>

<div><font face="courier new, monospace" size="1">  "Keep(NZTopo_Parse(PSS('$1'), PSS('$2'), PSS('$3'), PSS('$4'), PSS('$5')))" );</font></div><div><font face="courier new, monospace" size="1"># s = dot matches all chars including newline</font></div>

<div><font face="courier new, monospace" size="1"># e = backreference substitution by expression</font></div><div><font face="courier new, monospace" size="1"># i = case insensitive</font></div><div><font face="courier new, monospace" size="1"># m = multiline</font></div>

<div><font face="courier new, monospace" size="1"># uses lazy evaluation, preserves leading and trailing white space</font></div><div><font face="courier new, monospace" size="1"># Keep prevents PmWiki markup being applied</font></div>

<div><font face="courier new, monospace" size="1">#</font></div><div><font face="courier new, monospace" size="1">/** Main NZTopo parser</font></div><div><font face="courier new, monospace" size="1"> *   /param   arguements as documented above</font></div>

<div><font face="courier new, monospace" size="1"> *   /return  The HTML-formatted NZTopo markup wrapped in a <div> of class "nztopo", see <a href="http://www.topomap.co.nz/">http://www.topomap.co.nz/</a>.</font></div>

<div><font face="courier new, monospace" size="1"> */</font></div><div><font face="courier new, monospace" size="1">function NZTopo_Parse($coords, $height, $width, $pin, $p5) {</font></div></div><div><br></div><div><br></div>

<div><br></div><div><br></div><div>Useful references:</div><div><a href="http://www.pmwiki.org/wiki/PmWiki/CustomMarkup">http://www.pmwiki.org/wiki/PmWiki/CustomMarkup</a></div><div><a href="http://www.pmwiki.org/wiki/PmWiki/CustomMarkupAlt">http://www.pmwiki.org/wiki/PmWiki/CustomMarkupAlt</a></div>

<div><br></div>