mFoo = foo;
mBar = bar;
// convert to
this.foo = foo;
this.bar = bar;
How to use a regex to handle this substitution? 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
Update
L
above is a typo. It should be \L
according to JetBrains' document
If your regular expression has named capturing groups, then you should use named backreferences to them in the replacement text. The regex (?' name'group) has one group called “name”. You can reference this group with ${name} in the JGsoft applications, Delphi, .
Normally, within a pattern, you create a back-reference to the content a capture group previously matched by using a backslash followed by the group number—for instance \1 for Group 1. (The syntax for replacements can vary.)
They are created by placing the characters to be grouped inside a set of parentheses ( , ) . We can specify as many groups as we wish. Each sub-pattern inside a pair of parentheses will be captured as a group. Capturing groups are numbered by counting their opening parentheses from left to right.
Numbers for Named Capturing Groups. Mixing named and numbered capturing groups is not recommended because flavors are inconsistent in how the groups are numbered. If a group doesn't need to have a name, make it non-capturing using the (?:group) syntax.
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\)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With