[pmwiki-users] Release: GoogleMapsInterface

Patrick R. Michaud pmichaud at pobox.com
Wed Dec 6 13:40:41 CST 2006


On Wed, Dec 06, 2006 at 01:45:43PM -0500, Craige Leeder wrote:
> Hans wrote:
> >Tuesday, December 5, 2006, 10:07:22 PM, Craige wrote:
> >
> >to avoid the necessary space at (:map-end :)
> >you could try this regex instead:
> >
> >'/\(:map(-location|-end)\\s*(.*?):\)/ie'
> >
> 
> I tried the expression, and it was unsuccessful on a match. I assumed it 
> wouldn't, as \\s is looking for a literal '\', and a possible 's'. 

No, PHP converts '\\s' to be a backslash+'s', and then PCRE sees
the resulting '\s' as being the metasequence for matching whitespace.

PHP has some odd handling of backslashes in quoted strings, so
to avoid potential confusion I've simply gotten in the habit of
always using '\\' or "\\" whenever I want a single backslash in
the resulting string, even if PHP doesn't specifically require it.  
In the case of PCRE's \s construct, one can write either '\\s' or '\s'
and it will end up working out correctly, because PHP will convert
both of these to be a backslash+'s' string.

If one needs two backslashes in a string (e.g., to get PCRE to 
have \\ to match a literal backslash), then in PHP one has to
write either '\\\\' or "\\\\".

Pm




More information about the pmwiki-users mailing list