P粉1166315912023-08-26 13:50:46
The problem is that the newly introduced v
flag imposes more restrictions on escaping rules. Since it allows subtraction and intersection of character classes, the literal -
at the end of the character class cannot remain unescaped.
Therefore, if you use the u
flag, there is no such restriction, and if you use the v
flag, there is such a restriction. See.
console.log(/^[a-zA-Z0-9+_.-]+@[a-zA-Z0-9]+\.[a-zA-Z0-9]+$/u.test("myname@somesite.com")) console.log(/^[a-zA-Z0-9+_.\-]+@[a-zA-Z0-9]+\.[a-zA-Z0-9]+$/v.test("myname@somesite.com"))