[RESOLVED] Search - Ignore Comments

At the moment, when I do Ctrl-F to find in a file, the options are:
Case Sensitive
Match whole words only
Regex

Can we have another option that says:
Ignore results in comments

1
3 comments

No, the search is not context aware.
You either have to use the "regular", "Find Usages" and its variants or use the (not-so-intuitive) structural search.

0

I was helped out by a collegue with a nice piece of regex
^((?!.(//|///)).key.*)$

where "key" is the search term

1

JSLint highlighted all of my uses of single-quotes to delimit strings, but JSLint is comment-aware.  So when I tried to use WebStorm to repair the problems found by JSLint I was surprised WebStorm didn't discriminate between comments and code.  I used this regex to change single to double quotes:

  • Find: '([^\']*)'
  • Replace with: "$1"

But a single, single quote in a comment (e.g., the word that's) caused each subsequent match to END with the beginning of a string in code and BEGIN with the end of a string.

The workaround I finally arrived at was to use WebStorm replace's "In Selection" checkbox and work a section at a time, avoiding quotes containing comments.  Still, it seems as though if JSLint can discriminate, WebStorm should be able to.

1

Please sign in to leave a comment.