I have a problem with sublime text which should be generally all editors. When I have a regular expression like this.
listRegex = re.findall(r'[*][[][[].*', testString)
All the text after the regular expression will be incorrectly highlighted, because of the [[]
, specifically the [
without a close bracket. While the intention of this regular expression is correct, the editor doesn't know this.
This is just an annoyance I don't know how to deal with. Anyone know how to fix this?
While it doesn't really answer your question, you could just use a different regex:
listRegex = re.findall(r'\*\[\[.*', testString)
Or you can prevent any regex highligting:
listRegex = re.findall(R'[*][[][[].*', testString)
Add the following to .../Packages/Python/Regular Expressions (Python).tmLanguage
on line 266 (first and third blocks are context):
<key>name</key>
<string>constant.other.character-class.set.regexp</string>
<key>patterns</key>
<array>
<dict>
<key>match</key>
<string>\[</string>
</dict>
<dict>
<key>include</key>
<string>#character-class</string>
</dict>
That's a known bug of Sublime Text's Python Syntax Highlighter that only affects raw strings.
By the way in a regex you can match a special character in two ways:
Enclosing it in a square bracket: [[]
Escaping it with a backslash: \[
The second one is preferred, so you can change your code to:
listRegex = re.findall(r'\*\[\[.*', testString)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With