Is search in a comment, best detection method?

I am using cm.getSearchCursor(“some text”) then findNext then getting the ‘from’ position.

I need to know if this section is currently in a block or line comment, essentially if that text is commented out.

What is the best approach, I have searched stack overflow and even here, is there a way to detect this?

Thank you

The getTokenTypeAt method might help—the result will match /\bcomment\b/ for positions that are in a comment.

Works perfectly, thank you!