TS-Rex lets you construct complex regular expressions through a chainable TypeScript API — and automatically infers the exact shape of named capturing groups at compile time. No moreDocumentation 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.
string | undefined surprises, no more lastIndex mutation bugs, no more unreadable raw regex strings.
Quickstart
Build your first type-safe regex pattern in under five minutes.
Installation
Install TS-Rex via npm, pnpm, bun, or jsr.
Core Concepts
Understand the AST engine, immutability, and phantom type state.
API Reference
Browse every builder method with signatures and examples.
Why TS-Rex?
Native JavaScriptRegExp is powerful but fragile. Regex patterns are opaque strings — one typo silently breaks your logic. Named capture groups require manual type casting. Global flag mutations cause subtle lastIndex bugs across executions. TS-Rex solves all three problems.
Static type inference
Named captures are inferred directly from your builder chain — no type assertions needed.
Stateless execution
Fresh
RegExp instances on every .exec() call prevent lastIndex mutation bugs entirely.Automatic escaping
.literal() and .anyOf() auto-escape special characters so your patterns are always safe.Zero dependencies
Built entirely on standard TypeScript and native
RegExp — nothing extra to install.Get started in 3 steps
Explore the docs
Character classes
.digit(), .wordChar(), .anyOf(), .range(), and more.Quantifiers
.optional(), .zeroOrMore(), .oneOrMore(), .times(), and lazy variants.Groups & alternation
Named captures, non-capturing groups, backreferences, and
.or().Flags
Global iteration, case-insensitive, match indices, Unicode sets, and more.
URL parser example
A real-world example combining captures, optionality, and character classes.
Escape hatches
.raw() and .rawClass() for power users who need full control.