[pmwiki-users] Release: GoogleMapsInterface

Patrick R. Michaud pmichaud at pobox.com
Wed Dec 6 14:56:54 CST 2006


On Wed, Dec 06, 2006 at 03:11:01PM -0500, Craige Leeder wrote:
> Patrick R. Michaud wrote:
> > Markup('map', '_begin', 
> >   '/\\(:map(-location|-end)(\\s.*?)?:\\)/ie',
> >   "CvtMarkup('$1', PSS('$2'))");
> >
> >The \s* approach above doesn't require the space (since \s*
> >will match an empty string), so what we really want is a
> >required space (i.e., \s) before any options.
> > 
> >
> Okay, I tried it, and it got me to the same place my most recent 
> expression got me: It matches the map-location, and map-end tags, but 
> not base map tag.
> 
> And also, I'm not sure what possessed me, or you to do it, but we don't 
> need the question marks. The asterisk means zero or more of the 
> preceding, so the question mark is not required after the asterisk, it 
> will pass not matching anything anyway.

Actually, in the general case the question mark _is_ needed.  

The difference between .* and .*? is that .*? matches the shortest
string possible, while .* matches the longest string possible.

So, for example, if we use .* instead of .*?, as in:

    Markup('map', '_begin', 
      '/\\(:map(-location|-end)?(\\s.*)?:\\)/ie',    
      "CvtMarkup('$1', PSS('$2'))");

and someone writes a markup line like

    (:map abc:) (:comment def:)

then the pattern for (:map:) inadvertently ends up matching both 
directives, with $2 set to "abc:) (:comment def".  Using .*? 
means that we stop at the first colon+paren that we find, while
using .* means that we'll stop at the last colon+paren that we 
find.

...snd we want the question mark at the end of (\\s.*?)?  because
the space is required only if there are any arguments.  Without
that question mark, we can't match (:map:), (:map-location:), or 
(:map-end:).

Lastly, it's probably worth pointing out that all of PmWiki's
core directives use "end" without a hyphen, as in (:ifend:), 
(:tableend:), (:markupend:), (:divend:), etc.  To avoid confusion
among authors, you might want to follow (or at least allow) the same 
convention for (:mapend:):

    Markup('map', '_begin', 
      '/\\(:map(-location|-?end)?(\\s.*?)?:\\)/ie',    
      "CvtMarkup('$1', PSS('$2'))");

Pm




More information about the pmwiki-users mailing list