Think of the `u` flag as a strict mode for regular expressions.

`/\a/u` throws, because there is no reason to escape `a` as `\a` --
therefore, if such an escape sequence is present, it's likely a user error.
The same goes for `/\-/u`. `-` only has special meaning within character
classes, not outside of them.

On Fri, Sep 20, 2019 at 11:22 AM kai zhu <kaizhu...@gmail.com> wrote:

> jslint previously warned against unescaped literal "-" in regexp.
>
> however, escaping "-" together with unicode flag "u", causes syntax error
> in chrome/firefox/edge (and jslint has since removed warning):
>
> ```javascript
> let rgx = /\-/u
> VM21:1 Uncaught SyntaxError: Invalid regular expression: /\-/: Invalid
> escape
>     at <anonymous>:1:10
> ```
>
> just, curious on reason why above edge-case is a syntax-error?
> _______________________________________________
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to