/hell\u{6F}/u.test('hello'); // -> true /hell\u{6F}/.test('hello'); // -> false
Explain the specifics of the /u
flag in regular expressions.
/hell\u{6F}/u.test('hello'); // -> true /hell\u{6F}/.test('hello'); // -> false
Explain the specifics of the /u
flag in regular expressions.
Everything is just like an ax:
With this flag, the regular form understands expressions like \u{6f}
inside the regular schedule, as a Unicode character, without it - understands as a string of consecutive characters u, {, 6, f,}
The main specifics are the same here: this is a feature appeared in the ecmascript-6 standard, that is, without any compilation in ecmascript-5, the code will not be understood by all browsers.
There is another small nuance:
Let x be not an escape symbol, then it is a syntactically valid regular schedule:
var c = /\x/
And this is not:
var c = /\x/u
Source: https://ru.stackoverflow.com/questions/559095/
All Articles