Flags modify how the regex engine interprets and executes a pattern. In TS-Rex, flag methods are more than thin wrappers around the nativeDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/fajarnugraha37/ts-rex/llms.txt
Use this file to discover all available pages before exploring further.
RegExp flag letters — several of them alter the TypeScript return type of .exec() in a way that is tracked through the TFlags generic parameter. Calling .global() changes the return type from a single-match discriminated union to an IterableIterator. Calling .withIndices() adds an indices property to every successful match. The table below summarises the type-level impact of each flag, followed by full method references.
Flag summary
| Method | Flag letter | TFlags key set | Return type effect |
|---|---|---|---|
.global() | g | { global: true } | exec() returns IterableIterator<SingleMatch> |
.ignoreCase() | i | { ignoreCase: true } | No change to return type |
.multiline() | m | { multiline: true } | No change to return type |
.dotAll() | s | { dotAll: true } | No change to return type |
.withIndices() | d | { hasIndices: true } | Adds indices property to SingleMatch |
.unicode() | u | { unicode: true } | No change to return type |
.unicodeSets() | v | { unicodeSets: true } | No change to return type |
.sticky() | y | { sticky: true } | No change to return type |
.global()
Enables global matching. The g flag causes .exec() to find all non-overlapping matches across the entire input instead of stopping at the first. At the type level, TFlags is widened to include { global: true }, which changes MatchResult from SingleMatch | FailedMatch to IterableIterator<SingleMatch>.
Signature
global: true
FailedMatch), you do not use an if (result.isMatch) guard — you iterate directly. An empty iterator means no matches were found.
Example
TS-Rex creates a fresh
RegExp instance on every .exec() call. This eliminates the lastIndex bug that affects native global regexes, where a second call on the same RegExp instance resumes from a stale position..ignoreCase()
Enables case-insensitive matching. The i flag causes the engine to treat uppercase and lowercase letters as equivalent.
Signature
.multiline()
Enables multiline mode. The m flag changes the meaning of ^ and $ so they match the start and end of each line within the string, not just the start and end of the entire input.
Signature
.dotAll()
Enables dotAll mode. The s flag causes .anyChar() (.) to match any character including newline characters (\n, \r, \u2028, \u2029). Without this flag, . does not match newlines.
Signature
.withIndices()
Enables indices mode. The d flag causes the engine to compute start and end character indices for the full match and every named capture group. At the type level, TFlags is widened to include { hasIndices: true }, which adds a readonly indices property to SingleMatch.
Signature
SingleMatch
indices is a [start, end] tuple where start is the inclusive start index and end is the exclusive end index, matching the slice convention of String.prototype.slice.
Example
The
indices property key is hasIndices internally (matching the RegExp.prototype.hasIndices property name), even though the flag letter is d. Use .withIndices() — not .hasIndices() — to enable this mode..unicode()
Enables Unicode mode. The u flag treats the pattern and the input as a sequence of Unicode code points rather than UTF-16 code units. This is required for .unicodeCodePoint() (\u{...}) and .unicodeProperty() (\p{...}) to work correctly.
Signature
.unicodeSets()
Enables Unicode sets mode (ES2024). The v flag is a superset of u, additionally enabling set operations (--, &&) and string literals inside character classes. You cannot use both u and v flags on the same regex.
Signature
.sticky()
Enables sticky mode. The y flag causes the engine to match only at the exact position indicated by lastIndex on the underlying RegExp instance. Because TS-Rex creates a fresh RegExp on every .exec() call (with lastIndex starting at 0), sticky mode effectively anchors the match to the start of the string unless you interact with compiled.native directly.
Signature