On Wed, August 9, 2006 5:07 am, Dave M G wrote:
> The brackets indicate a sub-expression.

The parens indicate that you want to CAPTURE the matched characters.

Inside of [ ] the parens would be a sub-expression, however.

> First question, why is there an extra backslash before the space
> marker
> "\s"? Isn't that an escape character, so wouldn't that turn the
> following space marker into a literal backslash followed by an "s"?

PHP uses \ as an escape character.
PCRE *also* uses \ as an escape character.

So, in PHP, the \\ *does* turn into \s -- You are correct on that.

In PCRE \s means "whitespace" -- the s is not just an 's' character
alone, it's an \s which means whitespace.

> Hmm... does the (.*) after the second "\s" mean to match all the
> whitespace found? For example if there happened to be two space
> characters instead of just one?

No.

The one I gave, with \\s* would match all the whitespace found,
whether it was 2 spaces, or a thousand tabs, or any combination of
space, tab, newline.

* only applies to the one "thing" before *

In this case, it's a '.', which means "any character at all"

> The PHP manual says the "$" means to "assert end of subject". Which I
> think means "stop looking for any more matches".

Nope.

It means "END OF STRING"

Or, in a multi-line match, "END OF LINE" or "END OF STRING"

> So basically I'm confused about the extra escape slashes.

You are not alone :-)

Some list members consider them bogus and distracting.

But both PHP and PCRE use \ as an escape character.

So using \\s for PHP to get \s, and that "feeds" \s to PCRE to mean
"whitespace" seems more clear to some than just "\s" which looks like
you want PHP to do something with that \s like it would for \t, \r,
\n, or all the other funky \ things PHP has inside of ""

\\s is less ambiguous, to some readers
\s is less cluttered, to some readers

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to