How to repeat text matching regular expression?

I am trying to add log4j to legacy software using eclipse search / replace.

The idea is to find all the class declarations and replace them with the declaration itself plus the registrar definition in the next line.

Search

".*class ([A-Z][a-z]+).*\{"

replace:

"final static Logger log = Logger.getLogger($1.class);"

How can I add a matched pattern (class definition) to the replacement string?

+5
source share
2 answers

I think you need this:

Search:

(.*class ([A-Z][a-z]+).*\{)

replace:

$1\Rfinal static Logger log = Logger.getLogger($2.class);
+3
source

You can always grab it all and insert it. The internal capture group lives in the second reverse direction.

Search:

(.*class ([A-Z][a-z]+).*\{)

Replaced by:

$1 final static Logger log = Logger.getLogger($2.class);

+1
source

All Articles