The eight flags
JavaScript regex flags as of ES2024:
i— case-insensitiveg— global (find all matches; enablesmatchAllandreplaceAll)m— multiline (^and$match line boundaries)s— dotAll (.matches newlines)u— Unicode (treats pattern and string as Unicode code points)y— sticky (matches starting atlastIndexonly)d— has indices (match objects include start/end offsets for groups; ES2022+)v— Unicode sets (extended Unicode features; ES2024)
Combining flags
Flags are concatenated in any order: /pattern/gimsu. Order doesn't matter; duplicates are an error.
The Unicode flag (/u)
Without /u, JavaScript treats astral plane characters (emoji, rare Asian scripts) as surrogate pairs — one character looks like two to the regex. With /u, characters are treated as Unicode code points.
Always use /u when matching Unicode text. It enables \p{...} Unicode category escapes and makes . match a single emoji as one unit.
The sticky flag (/y)
/y is /g's pickier cousin: it matches ONLY at lastIndex. Useful for tokenizers that consume input piece by piece without skipping junk between matches.