Marcus
Marcus

Reputation: 561

phpstorm regex search and replace

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

Upvotes: 5

Views: 4744

Answers (1)

Michael
Michael

Reputation: 3332

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

Upvotes: 12

Related Questions