Page 1 of 1

preg_replace with backslash, dollar sign and double quote

Posted: Sun Nov 03, 2002 9:35 pm
by lyoute
$str = '\\\\$hello \\\"world';
$str = preg_replace("/\\\*\$/","\$",$str);
$str = preg_replace("/\\\*\"/","\"",$str);
print $str;

output :
$hello "world$

but what i expect is \$hello \"world

any problem with my regular expression?

Posted: Mon Nov 04, 2002 12:33 am
by lyoute
oh i got it...

$str = preg_replace("/\\\*\\$/","\\\\$",$str);
$str = preg_replace("/\\\*\"/","\\\"",$str);

\\\\$ = "\\"."\\$"
\\\" = "\\"."\""
arghhh....so tricky... :(