Re: preg_match
| From: | Jasper Bryant-Greene | Date: | Tue, 23 Aug 2005 09:21:36 +0000 |
| Subject: | Re: preg_match | ||
| References: | 1 2 3 4 5 6 7 8 9 10 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-221155@lists.php.net to get a copy of this message | ||
Robin Vickery wrote:
Both of these will fail to compile: preg_match( '/\\7abc/', $myString); preg_match( '/\7abc/', $myString); Both of these are fine: preg_match( '/\\abc7/', $myString); preg_match( '/\abc7/', $myString); In fact they behave *exactly* as if you hadn't doubled them up. You've not achieved anything, but you've made your regexp just a little more difficult to read and maintain.You achieved something. You made your code syntactically correct, even if PHP lets you get away with things like \a inside single-quoted strings.
The proper syntax is to double the backslash, not to rely on the fact that the character following it happens to not make it a special character. Jasper\\ always works \ only works sometimes, depending on what character follows it.No it doesn't. Indiscriminately doubling up all your back-slashes is not an alternative to actually learning the proper syntax.