"Jan Pieter Kunst" <de*****@cauce.org> wrote in message
news:42***********************@news.xs4all.nl...
: sbd! wrote:
: > I had a problem with string which have some \ chars at the end of the
: > string. For example:
: >
: > $String = "I want this **** out of here\\\\\\\\\";
: >
: > I needed to remove it useing regular expression...i thinked that
: > something like "/\\+$/" is enough but i was wrong. I made some tries
: > and finaly i removed "\" chars it with "/\\\+$/". It works (i'm proud
: > with myself :)), but i can't understand why \\\ matchs single \, and \\
: > not...
: >
:
: Because (as far as I understand it) backslashes have to be escaped
: twice: once for the regular expression engine, and once for PHP.
One way to get round this is to use single quotes instead:
'/\\+$/' gets round the esacaping problem. Don't double-quote PREG strings,
it gives you no end of trouble!
If you have to interpolate variable values into perl regexes, have a look at
http://php.net/preg_quote
Matt