Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

Is it possible to use the find feauture in NetBeans or other Java IDE excluding commented code from the results? How??

Given a project I'd like to find all the occurrences of a word without getting back possible matches that come from code that is commented. Am I the only one that needs something like this?

share|improve this question

closed as off-topic by Snowman, durron597, MichaelT, GlenH7, Ixrec May 3 at 9:53

  • This question does not appear to be about software development within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

I'm voting to close this question as off-topic because it is about a programming tool and it is too old to migrate to Stack Overflow. –  Snowman May 2 at 20:41

3 Answers 3

Find and replace tools are generally pretty simple and not intended to be that robust. They are really for quick and dirty operations or to ease navigation, not for generating accurate metrics.

If you need something like this you are likely going to have to find a way to create a regular expression, or create a script to run and find what you are looking for.

Large chunks of commented code is a thing of the past given the prevalence of version control, code that would be commented out can simply be deleted because a copy of that code is saved in the version history should it ever actually be needed to be referred to.

share|improve this answer

If you use regular expressions in the Find feature of Eclipse, you can do it; it's only a matter of finding the correct regular expression. I tried with several regular expressions for a while, but I wasn't able to find the correct one :(. The idea is to use a negative lookahead or lookbehind to ignore comment characters.

So if I'm looking for foobar in my code, but I'm trying to avoid '#'-style comments, I would do something like (?!#)foobar. The problem was it would match after the # on a line, so you need a way to look at the entire line.

Here is a related question that can help you: http://stackoverflow.com/questions/6772447/regex-match-but-not-if-in-a-comment

share|improve this answer

the "find" tool in IntelliJ IDEA (both commercial and community editions) allows you to exclude comments from results.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.