14

What's the syntax to perform a search/replace on Eclipse and use "match groups" (is that what it's called?)

On vi I do the following:

%s/log\(.*\)/log \1 debug/g 

And lines like this one:

log "Message" 

are replaced with:

log "Message" debug

What's the correct syntax for eclipse in the search/replace dialog box (beside checking up "Regular expressions")

Thanks.

OscarRyz
  • 196,001
  • 113
  • 385
  • 569

2 Answers2

37

Use $1 instead of \1

For the /g global replace flag, use the Replace All button:

eclipse find/replace dialog
(source: bpsite.net)

Note: The above is the Find/Replace dialog for a single file, comes up for Ctrl-F

For working across multiple files, default shortcut is Ctrl-H, and the dialogs are a bit different:

eclipse search & replace dialogs

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Peter Boughton
  • 110,170
  • 32
  • 120
  • 176
  • Then you may be interested in Vrapper, an Eclipse plugin that wraps around editors and makes them Vim-like. http://vrapper.sourceforge.net/home/ Doesn't do replacing, but still might be handy. :) – Peter Boughton Jul 08 '09 at 07:08
  • @Peter: I have tried vi plugins in some other tools but they only make things worst since then I don't know which tool am I. It interrupt my train of thought. – OscarRyz Jul 09 '09 at 02:37
2

In the Find Field: log(.*)

Int the Replace With Field: log$1 debug

AdamC
  • 16,087
  • 8
  • 51
  • 67