Regex Flags
Flags modify how a pattern behaves. Common flags: g (global), i (case-insensitive), m (multiline), s (dotAll), u (unicode).
Flags modify how a pattern behaves. Common flags: g (global), i (case-insensitive), m (multiline), s (dotAll), u (unicode).
/cat/g // g: find all matches
/cat/i // i: case-insensitive
/cat/gi // combine flags
// m: ^ and $ match line boundaries
/^\w+/gm // First word of each line
// s: dot matches newlines
/start.end/s.test("start
end"); // true
// u: full Unicode support
/\p{Emoji}/u.test("😀"); // true (Unicode property)
/^\p{L}+$/u.test("café"); // true (unicode letters)
Always use the u flag for patterns involving Unicode characters — without it, some characters may not match correctly.
More in JavaScript