I want to search my whole project for a certain string, but I only want results which are uncommented. It would be great if there was just an option to not include comments in the search results, but I don't see how to do this.
Is there a hidden option for this, or a trick? I could go back to the command line and use grep, but I prefer to have the results within eclipse so I can easily jump to the line number.
In "File Search", you can tick "Regular expressions" and use this regex to search for "some text" but exclude one-line (ie // ...
) java comments:
^(?!\s*//).*some text
There's probably a better way to express this. It would be difficult (impossible?) to to write a regex for multi-line comments ie /* ...many lines... */
EDIT:
This regex will also exclude all lines whose first character is *
- ie javadoc comments:
^(?!\s*(//|\*)).*some text
While lines that start with *
are not necessarily comments, it is rare indeed for java code.
You can limit your search results, from the Java Search tab, if you are employing Java Search in the first place.
Searches can be limited to References, Declarations, Implementors and selected other areas of the source code, instead of All ocurrences (which might be the default in your case).
If you are referring to plain text searches (the File Search tab), then you are out of luck.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With