Reputation: 21
as the following regExp:
var reg = /(\.[\u4e00-\u9fa5A-Z_])+/i;
reg.test('.a.s');
only the Chrome get false, other browsers and node all get true.
Is that because the Chrome regExp engine?
This problem was solved thanks to the anser of @Wiktor Stribiżew. Please refer to his answer.
======================================================================
This may be a bug of ES6 when perform RegExp. Someone has report the issue in both node and chrome community. Refer to these:
https://bugs.chromium.org/p/v8/issues/detail?id=5199
Upvotes: 2
Views: 133
Reputation: 626747
Latest Chrome versions run on V8 that is ES6 compliant.
So, the \u9fa5A
is treated as one code point rather than \u9fa5
and A
, see this test:
// Chorme 51.0.2704.103 m output is given on the right
console.log(
String.fromCharCode(parseInt("4e00", 16)), // => "一"
String.fromCharCode(parseInt("9fa5A", 16)), // => "署"
String.fromCharCode(parseInt("9fa5", 16)) // => "龥"
);
You need to make sure the \u
values are parsed correctly with \u{XXXX}
notation and /u
modifier (will work with ES6 only) or rearrange the character class parts as shown below:
console.log(/(\.[\u{4e00}-\u{9fa5}A-Z_])+/iu.test('.a.s'));
// or rearrange the ranges:
console.log(/(\.[A-Z_\u4e00-\u9fa5])+/i.test('.a.s'));
Upvotes: 3
Reputation: 1620
I have checked with the result. I have got only true result. Do you have any particular version or something?
Upvotes: 0