A TypeScript library that builds regular expressions from natural-language-style syntax with typed capture groups and optional compile-to-RegExp transforms.
Overview
magic-regexp is a TypeScript package that offers a compiled-away, type-safe, readable alternative to writing raw regular expressions. It requires TypeScript 5.0 or later.
At runtime the package is zero-dependency and minimal when you do not use a transform. It can also ship with a build transform that compiles patterns down to plain RegExp code. Capture groups are typed automatically, and the generated pattern can show on hover in the editor.
Syntax reads like natural language rather than dense regex symbols. You can use a lightweight runtime path or a pure RegExp compilation path for bundling. Related tooling includes verbal-expressions.
Key features
- Natural language regex syntax
- Typed capture groups
- Zero-dependency runtime
- Compile-to-RegExp transform
- Hover shows generated pattern
- TypeScript 5+ support
Use cases
- Readable TS regex builders
- Typed string parsing
- Compile-time regexp codegen
- Safer capture extraction
- Maintainable validation patterns