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, no registration required.

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
add comment

2 Answers

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
add comment

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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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