I trying to regex replace echo $review->helpful;
with echo stripslashes($review->helpful);
in PHPstorm without any luck.
I tried echo \$.*\;
with echo stripslashes($1);
but didn't worked I get malformed replacement string.
Any help will be appreciated.
Thanks
The Regex. Replace(String, String, MatchEvaluator, RegexOptions) method is useful for replacing a regular expression match if any of the following conditions is true: If the replacement string cannot readily be specified by a regular expression replacement pattern.
To use RegEx, the first argument of replace will be replaced with regex syntax, for example /regex/ . This syntax serves as a pattern where any parts of the string that match it will be replaced with the new substring. The string 3foobar4 matches the regex /\d. *\d/ , so it is replaced.
I'm not familiar with phpstorm
, but the reason you're getting a malformed replacement string
error is probably because you're using $1
to reference the first grouping, when there is no first grouping.
Try using this:
echo \$(.*?);
And replace again with this, like you originally did:
echo stripslashes($1);
Basically all I did was group .*
so that $1
would be able to reference it, and added a lazy modifier to the star just to avoid any weird stuff happening later on in the parse. I also removed the \
, since ;
itself doesn't stand for anything in regex, escaping it is unnecessary.
Here's a test to verify that it works: http://fiddle.re/9e47
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With