You probably mean any comments, both single- (//
) and MULTI-LINE (/**/
).
The other answers only deal with single-line-comments. So here comes my VS Code-compatible Regex for both of them at the same time:
(?<!//.*)(?!(/\*).*)YOUR_SEARCH_TERM(?![^/\*]*?\*/)
Explanation:
(?<!//.*)
is a negative look-behind against single-line-comments (//
)
(?!(/\*).*)
invalidates your search term if it is preceded by /*
(?![^/\*]*?\*/)
invalidates your search term if it is followed by */
(short of a /*
between your search term and itself, because then your search term would be outside of /**/ and you want it to be matched again).
To use it in VS Code, just type Ctrl
+ F
and tick the regex-icon in the search-field popping up (with void being your exemplary search term):
