I have this line in my Javascript code:
var regex = /===Hello===\n/;
JsHint gives me a warning in this line:
A regular expression literal can be confused with '/='`
…but I don’t know what’s wrong with this regular expression? How can I avoid this warning?
The problem is that
/=could be interpreted as a division and assignment, rather than the start of a regular expression literal.You can avoid the warning by using the
RegExpconstructor instead:There doesn’t appear to be any option you can set to tell JSHint (or JSLint for that matter) to ignore
/=, so your choice is either to work around it or ignore the warning.