+1

Regex/Javascript syntax highlighting bug

Austin Condiff 4 years ago • updated by Rockallite Wulf 3 years ago 1

I am using regex to validate an email input field as described here: http://www.regular-expressions.info/email.html


When I use that regex in my javascript, the syntax in rest of my document after the regex is incorrectly highlighted. Try copying and pasting the following code into a javascript file.


if($('form.contact input.email').val() == '' || !$('form.contact input.email').val().match(/[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/)) {

        hasError = true;

        $('form.contact input.email').addClass("error");

        console.log('Email is at fault');

}


Is anyone else having this issue? I am using ST3, pretty sure it does it in 2 as well.


This works for me:
http://www.sublimetext.com/forum/viewtopic.php?f=3&t=8495

For Sublime Text 3 for OS X, you need to extract JavaScript.tmLanguage file first:
cp /Applications/Sublime\ Text.app/Contents/MacOS/Packages/JavaScript.sublime-package /tmp/JavaScript.zip
unzip /tmp/JavaScript.zip -d /tmp/JavaScript
cp /tmp/JavaScript/JavaScript.tmLanguage ~/Library/Application\ Support/Sublime\ Text\ 3/Packages/JavaScript/JavaScript.tmLanguage
open ~/Library/Application\ Support/Sublime\ Text\ 3/Packages/JavaScript/
Then edit JavaScript.tmLanguage file as the post said (in line 650):
<string>(?<=[\s\[\,=(:]|^|return|&&|\|\||!)\s*(/)(?![/*+{}?]|[^/]*$)</string>
Save the file, there should be an immediate effect on the opened JavaScript files.