Contains utility functions for regular expressions.
| Function | Description |
|---|
| escapeRegExp | Escapes special characters in a string to safely use it within a regular expression. |
| getMandatoryNamedGroup | Reads a mandatory named capture group from a regex match. Use this for a named group that is ALWAYS present when the pattern matches — not wrapped in an optional (?:…)? / (…)?. Returns the captured string (which may be '' for a zero-width match such as \w*), throwing if the group — or the match’s groups object — is absent, so a pattern change that drops the group fails loudly instead of silently yielding a wrong value. Prefer this over match.groups?.[name] ?? '': for a mandatory group that fallback is a never-taken (dead) branch that fails a 100%-branch coverage gate, whereas the throw here lives inside ensureNonNullable (already covered), leaving no inline branch at the call site. For a group that may legitimately be absent, use getOptionalNamedGroup and default its null with ?? …. |
| getOptionalNamedGroup | Reads an optional named capture group from a regex match, distinguishing an absent group from a present empty one. Returns the captured string when the group participated in the match — which may be '' for a zero-width match such as \w* — or null when the group, or the match’s groups object, is absent (e.g. an optional (?:…)? group that did not match). Because null is returned only for a genuinely-absent group, a caller’s ?? <default> is a live branch rather than the dead one that match.groups?.[name] ?? '' leaves for a mandatory group. For a group that must always be present, use getMandatoryNamedGroup. |
| isValidRegExp | Checks if a string is a valid regular expression. |
| oneOf | Combine multiple regexes into one alternation, handling flags. |