Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to replace in WebStorm/PhpStorm with regex

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?

like image 431
ndemoreau Avatar asked Apr 15 '15 08:04

ndemoreau


People also ask

Can I replace with regex?

replace in JavaScript. 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.

How do you replace special characters in regex?

If you are having a string with special characters and want's to remove/replace them then you can use regex for that. Use this code: Regex. Replace(your String, @"[^0-9a-zA-Z]+", "")


1 Answers

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

like image 81
Wiktor Stribiżew Avatar answered Sep 28 '22 02:09

Wiktor Stribiżew