RegEx backreferences in IntelliJ

Dónal picture Dónal · Sep 14, 2009 · Viewed 23.3k times · Source

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.

Answer

Steve K picture Steve K · Sep 14, 2009

IntelliJ uses $1 for replacement backreferences.

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.