Take the 2-minute tour ×

In the eclipse workspace search (CTRL+H) what regular expression could be used to find occurrences of a word that do not begin with 2 leading forward slashes (/) - or in other words, are not commented?

For example //var_dump and // var_dump is what is not to be matched, but var_dump is what is to be matched.

share|improve this question

2 Answers 2

up vote 1 down vote accepted

The following regex in the file search tab would do it:

(?<!//)[ \t]*var_dump

If you only care about the first word on a line, precede it with a caret:

^(?<!//)[ \t]*var_dump

The (?<!//) part is a negative lookbehind - it only matches thing that do not have the contents of the brackets before the thing you are looking for.

However, if you are looking for variables that are not commented rather than not preceded by the specific combo "//", you might be better off using a syntax-aware search, which depends on the language used. For example, this regex will still match /* var_dump */, which you may or may not want to happen. A syntax-aware search would know this is commented.

If you look in the Search window, you will see a "Java Search" tab and tabs for other plugins you might have (I have "C/C++ Search" and "Git Search" for example). In these tabs, you can choose to search only for functions, variable, classes, or whatever else makes sense in that language.

A further thing you might want is to hit Ctrl-Shift-G on a word and it will list all the references to this object in your code - very useful when trying to track down what is calling your function or using your variable.

share|improve this answer
That worked perfectly! I wasn't too concerned about the syntax-aware search this time. I wish there was a shortcut like that which would search the working set instead of workspace. Thanks for the info –  Mark Aroni Dec 3 '12 at 18:35
If you mean the reference search, you can right click and choose References -> Working Set... as well. You can also assign a key shortcut in Preferences -> General -> Keys, under "References in Working Set". –  Inductiveload Dec 3 '12 at 18:38
I thought that was ctrl+alt+g at a glance, that's really useful, thanks! –  Mark Aroni Dec 3 '12 at 18:51
Ctrl+alt+g is raw text search, so searching on "myfunc" will find all instances of that text, including "myfunc1" and "//comment about myfunc". Ctrl+Shift+g only looks for code that is actually referencing that exact thing (so no comments or "myfunc1"s) –  Inductiveload Dec 3 '12 at 18:57
Unfortunately Ctrl+Shift+G only works for the current file and not the working set/workspace, I needed a combination. Great info, thanks :) –  Mark Aroni Dec 3 '12 at 19:11

If you're looking for a variable name (or the name of any other kind of Java element), you could use the Java search instead of the File search. You don't have regular expression support, but the search knows you're looking for a variable/class name and so you don't have to worry about surrounding syntax.

share|improve this answer

Your Answer


