RegExp flags

Modifiers like g, i, m, s, u, y that change how a pattern matches.

Since ES3 Spec ↗

Syntax

/pattern/flags
new RegExp("pattern", "flags")

Examples

console.log("AbA".match(/a/gi));
Output
[ 'A', 'a', 'A' ]
console.log(/^b/m.test("a\nb"));
Output
true
console.log(/a.b/s.test("a\nb"));
Output
true

Notes

- `g` global, `i` case-insensitive, `m` multiline, `s` dotAll, `u` unicode, `y` sticky, `d` indices. - Inspect via `regexp.flags` or individual booleans like `regexp.global`. - `s` (dotAll) is ES2018; `d` (hasIndices) is ES2022.

Browser & runtime support

EnvironmentSince version
chrome 1.0
firefox 1.0
safari 1.0
edge 12
node 0.10

See also