SyntaxStudy
Sign Up
JavaScript Intermediate 5 min read

Regex Flags

Regex Flags

Flags modify how a pattern behaves. Common flags: g (global), i (case-insensitive), m (multiline), s (dotAll), u (unicode).

Example
/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)
Pro Tip

Always use the u flag for patterns involving Unicode characters — without it, some characters may not match correctly.