note 36602 added to pcre.pattern.syntax
| From: | eli dot gordon at no__spam dot care2 dot spamcom | Date: | Wed, 15 Oct 2003 23:19:11 +0000 |
| Subject: | note 36602 added to pcre.pattern.syntax | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-58670@lists.php.net to get a copy of this message | ||
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.
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"
preg_replace('/\\\b/', 'bar', 'foo \b');
returns what we expect: "foo bar"
I imagine what happens here is that the double-backslash is translated into a single backslash
character, as it is supposed to, but then the resulting "\b" is again evaluated, leaving
us with just the letter "b".
----
Manual Page -- http://www.php.net/manual/en/pcre.pattern.syntax.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+36602
Delete -- http://master.php.net/manage/user-notes.php?action=delete+36602&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+36602&report=yes
Search -- http://master.php.net/manage/user-notes.php