Sublime Forum

Invalid JS syntax highlighting -- regex inside array


The JavaScript.tmLanguage seems to have inaccurate results for the following string, though it is legal javascript:

var pl=/^\'(?:^\']|\'\')*\'/, /^(?:G+|y+|M+|k+|S+|E+|a+|h+|K+|H+|c+|L+|Q+|d+|m+|s+|v+|z+|Z+)/, /^^\'GyMkSEahKHcLQdmsvzZ]+/]; function ql(a){return a}

When we break it up onto different lines, it works fine.

var pl= /^\'(?:^\']|\'\')*\'/, /^(?:G+|y+|M+|k+|S+|E+|a+|h+|K+|H+|c+|L+|Q+|d+|m+|s+|v+|z+|Z+)/, /^^\'GyMkSEahKHcLQdmsvzZ]+/]; function ql(a){return a}

Looks like there’s an inaccurate lookbehind I don’t fully understand in the JavaScript.tmLanguage…



I use this in my JavaScript.tmLanguage. With this regex, your code seems to look fine for me.

[pre=#000000] (?<=\s\,=(:]|^|return|&&||||!)\s*(/)(?!/+{}?]|^/]$)[/pre]

There is a bunch of variations of fixes for JavaScript regex floating around in the forum. I can’t even remember how much of this is my fixes and how much is from another person. I am also sure this can be improved further, but hopefully this will help.