Re: preg_match

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

\\ 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.

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

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux