Sublime Forum

Valid regex break notation

#1

This is a valid regex instruction in JavaScript that breaks syntax
send = send.replace(/}]}"/,’}]}’);

All lines after this are considered text string.

0 Likes

#2

It might be valid, but it is a bit sloppy in my opinion.

} and ] are special characters in regex, and should be escaped if not used in the traditional sense to specify characters [a-z] or number of acceptable matches {3}. Though there are some situations where } and ] can be used without escaping, but this can make things not as clear without explicit escaping. If you simply escape } and ] in your regex, syntax issues will be cleared up. I personally don’t think this needs to be fixed because I like to escape these characters to show people after me that I truly intended these characters to be used explicitly and that I did not make a typo. I know opinions on this differ, but why make regex, which is difficult to read for many, even more confusing to read, but that is just my 2 cents.

0 Likes

#3

I don’t know all of the cases in which } and ] are okay if not escaped, but this should help if you are adamant in not escaping characters.

This allows the first characters in a regex expression to be } and ] without escaping.
[pre=#000000] (?<=\s\,=(:]|^|return|&&||||!)\s*(/)}]](?!/+{}?]|^/]*$)[/pre]

Edit: replace line 650 in JavaScript.tmLanguage with this

0 Likes

#4

Thx for the quick fix, that solved the issue.

0 Likes