I have this string
d = "&&hell+lo";
I want to prepand \
before all special characters. SO the expected output i want is
\&&hell\+o
Here i am doing in two regex but not giving the expected output:
rex1 = d.replace(/[+-=&&><!(){}[\]"~*?:\/]/g, "\\$&");
alert(rex1);
rex2 = d.replace(/&{2}/g, "\\$&");
alert(rex2);
I checked this link but could not find how to replace &&
in the given string.
I want to run this in both javascript and PHP also.
text.replace(/[+-=><!(){}[\]"~*?:\/]|&&/g, "\\$&")
work fine in JS but if i do
$pattern = "/[+-=><!(){}[\]\"~*?:\/]|&&/";
echo preg_quote("he+l&&lo", $pattern);
in PHP, its not working