How to use a captured group in the same regular expression

mFoo = foo;
mBar = bar;
// convert to
this.foo = foo;
this.bar = bar;

How to use regex to handle this replacement? Please help. Here is the method I used in Android Studio (IntelliJ IDEA)Edit → Find → Replace in Path

Text to find: m([A-Z])([A-Za-z0-9]+) = L$1$2
Replace with: this\.L$1$2 = L$1$2

Refresh

LAbove is a typo. This must be \Lconsistent with the JetBrains document.

+6
source share
2 answers

You can use the template with a backlink and group the last words after the "=":

Search text:

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

Replace:

this.L $ 1 $ 2 = $ 3

, . , ( ):

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

:

this\.L$1$2 = $3

, :

mContext = context

:

this.LContext = context

, "L", text/replace, , , " " :

this\.$3 = $3

, :

this.context = context

, !

+16

, :

This is text one$
This is text two!
Is this text three?

. 1. Android Studio " ", Ctrl + R 2. "" : ([[\\ ^\$.\| \? * +() {}]) 3 "Regex" 4. "replace" : \ $ 1

:

This is text one\$
This is text two\!
Is this text three\?
0

Source: https://habr.com/ru/post/1625689/


All Articles