I am after (if possible), a reg expression which will only replace questions marks "?" with "'" where it is not followed by the "=" symbol in my string?
e.g. this is something?, but this will remain?=forever
should end up as:
this is something', but this will remain?=forever
Thanks
Mu
Just check this.. Simple one without regex ( I don't know regex :( )...:p
$string = "this is something?, but this will remain?=forever";
$my_secret_replace = "THISISANYTHINGWHICHWILLNOTINSTRING_OR_ANYRANDOMNUMBER";
$temp_string = str_replace("?=",$my_secret_replace,$string);
$temp_string = str_replace("?","'",$temp_string);
$final_string = str_replace($my_secret_replace,"?=",$temp_string);
This is simple using a negative lookahead: Use
\?(?!=)
$string = "String contains ? and ?= contains too?=?";
echo preg_replace("/\?([^=]|$)/", "'\\1", $string);