<div dir="ltr">Peter,<div style>I am having success with your method. I have a map of the garden, and I can place a single red "X" on the map using the markup</div><div style>  (:plant x=100 y=200:);</div><div style>
I used your code (mostly unchanged) in my config.php file. Thank you again!</div><div style><br></div><div style>The next thing I want to do is add this feature to my skin. I have already played around with my skin.tmpl file, but I am not sure how to do this conditional markup.</div>
<div style>Specifically:</div><div style>     1. If the page is in the Plant group, and the (:plant ... :) markup is used on the page, then include the garden map.</div><div style>     2. If I don't use the (:plant ... :) markup, the garden map is not included.</div>
<div style>Is this possible?</div><div style><br></div><div style>-Mark</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, May 9, 2013 at 12:38 AM, Peter Bowers <span dir="ltr"><<a href="mailto:pbowers@pobox.com" target="_blank">pbowers@pobox.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><span style="font-size:13px;font-family:arial,sans-serif"></span><br><div><div><div><div><div class="gmail_extra">
<br><div class="gmail_quote"><div class="im">On Thu, May 9, 2013 at 2:26 AM, Mark Lee <span dir="ltr"><<a href="mailto:mark.lee.phd@gmail.com" target="_blank">mark.lee.phd@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Thanks Peter. So helpful.<div>I have been reading about regular expressions. I am wondering why we need "\\" in the pattern <span style="font-size:13px;font-family:arial,sans-serif"> </span><span style="font-size:13px;font-family:arial,sans-serif">'/\\(:plant\\s*(.*?):\\)/e'? I know that "\(" means the "(" character, but what does "\\(" mean? The extra "\" is also used before "\s" and "\)". Is that part of pmwiki?</span></div>


<span><font color="#888888">
<div><span style="font-size:13px;font-family:arial,sans-serif"><br><br></span></div></font></span></div></blockquote></div><div><div><div><div><div><div><div><div><div><div><div>No, none of that has anything specific to do with pmwiki -- it's how PHP string handling and regex handling functions.<br>


</div><div><br>The following characters are "magic" in regular expressions:<br><br></div>(, ), \s, \d, *, ., etc.<br><br></div>By
 "magic" I mean they do not match themselves.  If in your regular 
expression you have an "a" it will match exactly that -- another "a".  
But if you have one of those "magic" characters then they have another 
meaning -- a '(' will not match a '(' in your regular expression (it 
tells the regex engine to start a pattern grouping) and the 2 characters
 '\s' will not match the 2 characters '\s' (they tell the regex engine 
to match any whitespace - space, enter, tab, etc.).<br><br>But what do 
you do if you want to match one of these "magic" characters?  In this 
case you want to match an open-paren and a close-paren so you can match 
the first and last characters of "(:plant ...:)".<br><br></div>In order to "unmagic" a "magic" character you escape it -- which means you put a backslash in front of it.<br><br>Thus
 '\(' matches '(' and '\)' matches ')' and '\\s' matches '\s' and etc.  
In each case the backslash removes the specialness of the character that
 follows.  (Note that in the case of the '\\s' you are actually 
"unmagic'ing" the backslash -- once the s doesn't have a backslash in 
front of it then it is just a normal character.)<br><br>Now, if that 
wasn't complicated enough ... we also have to work with the special 
rules of quoting strings in PHP.  And it truly gets complicated here 
between single quotes and double quotes (the rules are very different 
depending on which one you are using).<br><br></div>PHP uses the same 
idea of "escaping" to remove any special meaning of a character within 
quotes.  So if you wanted to put the string **I don't care** in single 
quotes without escaping it would look like this: 'I don't care'.  
Obviously this causes a problem because PHP sees the apostrophe between 
don and t and identifies it as the end of the string and the following 
**t care'** is simply a syntactical error.  So what you do is you escape
 the single quote with a backslash: 'I don\'t care'.  The backslash 
removes the special meaning of the single-quote as an 
end-of-string-delimiter and results in a valid string delimited by 
single quotes and containing a single quote.  The important thing to 
note is that the string NO LONGER CONTAINS THE BACKSLASH.  PHP removes 
the escaping backslashes as soon as they have done their job.  And even 
if from PHP's perspective they have no job (s has no special meaning 
within a PHP string so the backslash before \s doesn't really have a 
function) they still remove those backslashes.<br><br></div>But in order
 to have your regex contain a backslash you have to somehow make PHP 
allow the backslash through.  You do that by, you guessed it, escaping 
it with another backslash.  So a double-backslash (\\) in a PHP string 
will be converted to a single-backslash (\) by PHP string handling.  <br><br></div>So, back to the original example: <span style="font-size:13px;font-family:arial,sans-serif"></span><span style="font-size:13px;font-family:arial,sans-serif">'/\\(:plant\\s*(.*?):\\)/e'<br>


<br></span></div><span style="font-size:13px;font-family:arial,sans-serif">After PHP string handling finishes with it it will be stored internally like this: </span><span style="font-size:13px;font-family:arial,sans-serif"></span><span style="font-size:13px;font-family:arial,sans-serif">'/\(:plant\s*(.*?):\)/e' (I've just removed one of each of the pairs of backslashes.)<br>


<br></span></div><span style="font-size:13px;font-family:arial,sans-serif">NOW
 it is clear that the regex engine can look at \( and see it as matching
 a literal ( and it can see the \s and see it as matching any whitespace
 and etc.<br><br></span></div><div><span style="font-size:13px;font-family:arial,sans-serif">Sometimes
 the eval that is implicit in the /.../e requires more escaping and it 
gets really confusing -- you just have to think that each "pass" which 
allows escaping is going to remove one of any pair of backslashes.  So 
you count how many passes (first PHP string handling, then the regex 
engine, then the eval call -- and there can be others in there as 
well).  Eventually after you've pulled out all your hair you just start 
adding backslashes one at a time until it finally does what you want.<br></span></div><div><span style="font-size:13px;font-family:arial,sans-serif"><br></span></div><span style="font-size:13px;font-family:arial,sans-serif">How's that for a much longer and more in-depth explanation than you really wanted? :-)<span class="HOEnZb"><font color="#888888"><br>


<br></font></span></span></div><span class="HOEnZb"><font color="#888888"><span style="font-size:13px;font-family:arial,sans-serif">-Peter</span> <br></font></span></div></div><br></div></div></div></div></div></div>
</blockquote></div><br></div>