Reputation: 68962
I'm trying to add log4j to a legacy software using eclipse search/replace.
The idea is to find all class declarations and replace them by, the declaration itself plus the definition of the logger in the next line.
search
".*class ([A-Z][a-z]+).*\{"
replace:
"final static Logger log = Logger.getLogger($1.class);"
How can I prepend the matched pattern (the class definition) to the replace string?
Upvotes: 5
Views: 233
Reputation: 5023
I think you need this:
search:
(.*class ([A-Z][a-z]+).*\{)
replace:
$1\Rfinal static Logger log = Logger.getLogger($2.class);
Upvotes: 3
Reputation: 723698
You can always capture the whole thing and put it in. The inner capture group lives in a second backreference.
Find:
(.*class ([A-Z][a-z]+).*\{)
Replace with:
$1 final static Logger log = Logger.getLogger($2.class);
Upvotes: 1