Saturday, December 31, 2011

How to do exact search in Eclipse?

Many times I found myself confused/surprised while using Eclipse file search option (Search -> search or Ctrl + h). I couldn't find any option for EXACT string search. If you search for "foo", Eclipse will surprise you by showing results like "foo", "fooBar", "fool", "forgetFoo" etc etc i.e any string which contains foo (or whatever your search term is).


   
(No option for Whole word/Exact string search)

If you do a search in any particular file, using Ctrl + f. You can see option for "Whole word" or "Exact string".
  (Whole word option is available here)
After some Googling surprisingly I found that Eclipse don't provide any direct option to do whole word search in files. Don't worry, I said no DIRECT option but a small trick can rescue us.Regular expressions can be used with search term. To do a exact/ whole word search add \b to start and end of your search term. i.e. \bsearch_term\b.Also make sure you have selected "Regular Expression"  option.

  (Select "Regular expression" option and use \b before and after search term) 


Now you should be able to find EXACT word in files :D  
For more details  : Thread from Eclipse forum.  

~Ajinkya.



No comments:

Post a Comment