Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Idea find and replace with capture groups

I'm trying to find

 @BindView($ResId) internal lateinit var $FieldName: $Class

And replace with

private val $FieldName by bindView<$Class>($ResId)

What's the syntax to do that with Intellij Find & Replace feature?

like image 773
DmitryBorodin Avatar asked Aug 31 '25 22:08

DmitryBorodin


1 Answers

First, we have to activate the checkbox Regex in the Find & Replace bar if it should only affect the current file, or in the Replace in Path dialog for the whole project:

enter image description here

Using this regular expression with 3 capturing groups in the Find text field should work:

@BindView\((.*)\) internal lateinit var (.*): (.*)

Now we can use the variables $1 for $ResId, $2 for $FieldName and $3for $Class in the Replace text field:

private val $2 by bindView<$3>($1)
like image 118
Marcel Avatar answered Sep 04 '25 20:09

Marcel