A regular-expression flag modifies how a pattern matches or what information its results contain. Flags let the same pattern behave differently without changing its terms. section 12.2.1
JavaScript flags tune different parts of matching:
- d adds capture-group start and end indices to results; g matches all occurrences; i ignores case. section 12.2.1
- m makes ^ and $ match line boundaries; s lets . match newlines. section 12.2.1
- u and v enable Unicode features; v is generally preferred. y attempts a match at the last match position without gaps. section 12.2.1
Add flags to a pattern
Write flags after the closing slash, as in /test/ig, or pass them as the RegExp constructor’s second argument: new RegExp("test", "ig"). Here, i makes matching case-insensitive and g enables global matching. Global regexes continue matching through the string; local ones stop after a match. section 12.2.1 section 12.7

