Re: pcre.pattern.syntax.php (double-backslash in regex)
| From: | Curt Zirzow | Date: | Thu, 16 Oct 2003 22:22:47 +0000 |
| Subject: | Re: pcre.pattern.syntax.php (double-backslash in regex) | ||
| References: | 1 | Groups: | php.doc |
| Request: | Send a blank email to phpdoc+get-969356625@lists.php.net to get a copy of this message | ||
* Thus wrote Eli Gordon (egordon@itmeta.com):
>
> According to this doc:
> : if you want to match a backslash, you write "\\".
>
> This does not seem to be the case. In fact, you need three backslashes
> ("\\\"), not just two.
>
The context that the statement is used is describing syntax for
PCRE usage not php.
> For example, let's say we want to replace all instances of "\b" in the
> string "foo \b" with the word "bar":
>
> preg_replace('/\\b/', 'bar', 'foo \b');
> returns: "barfoobar \barbbar"
php passes '\b' to pcre, which treats that as a word boundry.
the 'foo \b' is untouched.
>
> preg_replace('/\\\b/', 'bar', 'foo \b');
> returns what we expect: "foo bar"
php passes '\\b' to pcre, and does what is defined in the section
you pointed out. 'foo \b' remains untouched.
Curt
--
"I used to think I was indecisive, but now I'm not so sure."