How can I use the captured group in the same regex

You can use a pattern with back-reference and grouping the last words after "=":

Text to find:

m([A-Z])([A-Za-z0-9]+) = (L\1\2)

Replace with:

this.L$1$2 = $3

After your comments, I understand that you have also problems with lowercase/uppercase characters. So try this pattern (I have also simplified the regex):

m(\p{Alpha})(\w+) = (((?i)\1)\2)

and this replace string:

this\.L$1$2 = $3

So with your example with an input text:

mContext = context

you obtain this:

this.LContext = context

I don't know if "L" specified in your text/replace string is your typo error or other but if it's so you can change the "replace string" in the following way:

this\.$3 = $3

So you can obtain this:

this.context = context

Let me know if this help you!


Thanks to Simona R., a simple example in Android Studio.

I want to replace

parentFragmentManager.let { dialogFragment.show(it, AlertDialogFragment.TAG) } 

to

dialogFragment.show(parentFragmentManager, AlertDialogFragment.TAG) 

in several classes so that two parameters may change.

Then I use replacement with $1 and $2:

parentFragmentManager.let \{ (\w+).show\(it, (\w+).TAG\) \}
$1.show\(parentFragmentManager, $2.TAG\)

enter image description here