How to replace in WebStorm/PhpStorm with regex

ndemoreau picture ndemoreau · Apr 15, 2015 · Viewed 13.2k times · Source

I want to replace

#{account_nbr}

with

{{account_nbr}}

in the find, I tried this:

\#\{()\w+\1\}

and in the replace, this:

{{\$1}}

The find seems to work but I can't get the backreference correctly.

What's wrong?

Answer

Wiktor Stribiżew picture Wiktor Stribiżew · Apr 15, 2015

You do not need any backreferences the way you are using them.

This is the regex you can use:

\#\{(\w+)\}

Replacement should be

{{$1}}

When you use \$, a literal $ is used, not the actual back-reference.

Regex demo