ruplacer icon indicating copy to clipboard operation
ruplacer copied to clipboard

Use capturing group next to literal

Open Masynchin opened this issue 3 years ago • 2 comments

Proposed tag: question.

I want to make all class {Name}Test to be internal class {Name}Test, so I try to run:

ruplacer 'class (\w+)Test' 'internal class $1Test'

But it doesn't work as expected. I avoided it with

ruplacer 'class (\w+)(Test)' 'internal class $1$2'

But how can solve my issue without adding second capturing group?

Masynchin avatar Jul 29 '22 01:07 Masynchin

@dmerejkowsky I am looking for help!

Masynchin avatar Aug 11 '22 19:08 Masynchin

Try putting a question mark after the + to make it non-greedy.

djmattyg007 avatar Dec 10 '22 21:12 djmattyg007