IntelliJ中的RegEx反向引用 [英] RegEx backreferences in IntelliJ
问题描述
我想使用IntelliJ的查找和替换功能来执行以下转换:
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
我尝试过以下方法:
要查找的文字: model.put \ ((。*),(。*)\)
替换为: model \ [\\\\\] = \\ 2
但是Intellij似乎无法识别 \\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.
推荐答案
IntelliJ使用 $ strong
用于替换反向引用。
IntelliJ uses $1
for replacement backreferences.
来自IntelliJ的帮助:
From IntelliJ's help:
有关正则表达式及其语法的更多信息,请参阅 java.util.regex 后引用应该是$ n,而不是\ n格式。
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.
这篇关于IntelliJ中的RegEx反向引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!