Sublime Forum

Comments being marked/color-coded as strings

#1

Hey! I’m rather new to programming and I am currently following some online courses and while doing that I noticed something funny.

While working with Regular Expressions, my comments become marked/color-coded as strings when using parentheses in that line. Now my question is, is there some kind of fault in the code or does sublime text simply do that?
Is there a way to change that?

0 Likes

#2

In Python regular expression, it is common to use raw strings (with the r in front: r'string'). Sublime defaults to highlighting raw strings for regular expression. Often when you use (?x) at the start of a regular expression, the regex engine will ignore white space and Python style comments.

Now the highlighter doesn’t look for the (?x) context, so it just assumes that # is a comment. I think the highlighter also won’t count the line if you have some content with parenthesis in it, which I don’t quite understand.

In short, the highlighter treats Python raw strings as Python regular expression and highlights them accordingly. But the highlight rules aren’t always the best, so there are some odd corner cases, as shown above.

1 Like