u
flag in regular expressions JS-0117 6713 '\u2028': 'u2028',
6714 '\u2029': 'u2029'
6715 }
6716 const V = /\\|'|\r|\n|\u2028|\u2029/g; 6717 (h.template = function (i, n, r) {
6718 !n && r && (n = r), (n = h.defaults({}, n, h.templateSettings))
6719 let t
6022 (h.countBy = k(function (n, r, t) {
6023 j(n, t) ? n[t]++ : (n[t] = 1)
6024 }))
6025 const S = /[^\ud800-\udfff]|[\ud800-\udbff][\udc00-\udfff]|[\ud800-\udfff]/g; 6026 (h.toArray = function (n) {
6027 return n
6028 ? h.isArray(n)
218 const b_copy = b.copy(b.offset, b.offset + 7)
219 const symbol = Buffer.from(b_copy.toBinary(), 'binary')
220 .toString()
221 .replace(/\ /g, '') 222 if (symbol == 'BLURT' || symbol == 'TESTS') {
223 nai_string = '@@000000021'
224 } else if (symbol == 'VESTS') nai_string = '@@000000037'
105 const b_copy = b.copy(b.offset, b.offset + 7)
106 symbol = Buffer.from(b_copy.toBinary(), 'binary')
107 .toString()
108 .replace(/\ /g, '') 109 b.skip(7)
110 // "1.000 BLURT" always written with full precision
111 amount_string = fromImpliedDecimal(amount, precision)
3068 return this
3069 }
3070 })
3071 const je = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([a-z][^\/\0>\x20\t\r\n\f]*)[^>]*)\/>/gi 3072 const qe = /<script|<style|<link/i
3073 const Le = /checked\s*(?:[^=]|=\s*.checked.)/i
3074 const He = /^\s*<!(?:\[CDATA\[|--)|(?:\]\]|--)>\s*$/g
It is recommended to use the u
flag with regular expressions.
The u
flag has two effects:
- It enables correct handling of UTF-16 surrogate pairs.
- It ensures the correct behavior of regex character ranges.
/^[👍]$/.test("👍") //→ false
/^[👍]$/u.test("👍") //→ true
For historical reasons, JavaScript regular expressions tolerate syntax errors.
For example, /\w{1, 2/
is a regex that would throw a syntax error, but JavaScript chooses not to.
It matches strings such as "a{1, 2"
instead.
This behaviour is defined in Annex B of the Javascript specification.
The u
flag disables the recovering logic Annex B
of the Javascript specification.
This way, you can find errors early.
It can therefore be thought of as a "strict mode" for RegEx literals.
This issue is raised when:
- A regular expression contains unicode property escapes i.e \p{<property-name>}
- A regular expression contains 4 bytes characters like emojis or some special characters
const a = /aaa/
const b = /bbb/gi
const c = new RegExp("ccc")
const d = new RegExp("ddd", "gi")
const a = /aaa/u
const b = /bbb/giu
const c = new RegExp("ccc", "u")
const d = new RegExp("ddd", "giu")
// This rule ignores RegExp calls if the flags are not a compile time constant.
function f(flags) {
return new RegExp("eee", flags)
}