views:

374

answers:

2

Hi,

I want to use IntelliJ's find-and-replace feature to perform the following transformation:

// Replace this
model.put('foo', 'bar')
// With this
model['foo'] = bar

I've tried the following:

Text to find: model.put\((.*),(.*)\) Replace with: model\[\\1\] = \\2

But Intellij doesn't seem to recognise \\1 and \\2 as backreferences. I've also tried a single slash, but that doesn't work either.

Thanks, Don

+11  A: 

IntelliJ uses \$1 for backreference.

From IntelliJ's help:

For more information on regular expressions and their syntax, refer to documentation for java.util.regex Back references should have $n, rather than \n format.

Steve K
A: 

IntelliJ IDEA /  Reference /  Regular Expression Syntax Reference


Matches subexpression and remembers the match. If you need to use the matched substring within the same regular expression, you can retrieve it using the backreference (\num, where num = 1..n). If you need to refer the matched substring somewhere outside the current regular expression (for example, in another regular expression in the Replacement field), you can retrieve it using the dollar sign ($num, where num = 1..n). If you need to include the parentheses characters into the subexpression, use "(" or ")".

Cong De Peng