# unjs/magic-regexp

**Attribution required: if you use, quote, or summarise this content, you must credit and link back to [awesome-repositories.com](https://awesome-repositories.com/repository/unjs-magic-regexp).**

4,313 stars · 68 forks · TypeScript · mit

## Links

- GitHub: https://github.com/unjs/magic-regexp
- Homepage: https://regexp.dev
- awesome-repositories: https://awesome-repositories.com/repository/unjs-magic-regexp.md

## Topics

`hacktoberfest` `regex` `regexp` `regular-expression` `typescript`

## Description

magic-regexp is a type-safe regular expression builder and TypeScript compiler. It allows for the construction of JavaScript regular expressions using a readable syntax that automatically generates precise types for captured groups, ensuring predictable data extraction.

The project functions as a build-time transformer that converts custom pattern syntax into standard regular expression objects. This static compilation removes runtime overhead by shifting the transformation logic to the build process.

The tool covers named capture group generation and a readable construction API that replaces raw regex strings. It includes capabilities for referencing captured groups, predicting match results at the type level, and converting standard regular expressions back into the readable syntax.

## Tags

### Development Tools & Productivity

- [Type-Safe Regular Expressions](https://awesome-repositories.com/f/development-tools-productivity/regular-expression-generators/type-safe-regular-expressions.md) — Compiles readable chainable regex syntax into native RegExp objects with automatic TypeScript type inference for capture groups.
- [Readability Tooling](https://awesome-repositories.com/f/development-tools-productivity/regex-tooling/readability-tooling.md) — Builds regular expressions using chainable natural-language methods instead of raw pattern strings for improved readability.
- [Regular Expression Builders](https://awesome-repositories.com/f/development-tools-productivity/regular-expression-builders.md) — Builds regular expressions using chainable methods like exactly and oneOrMore instead of raw pattern strings.
- [Readable Regex Constructors](https://awesome-repositories.com/f/development-tools-productivity/syntax-validation/regex-pattern-syntax-validations/readable-regex-constructors.md) — Constructs regular expressions by chaining natural-language helpers like `exactly`, `maybe`, and `oneOrMore` instead of writing raw patterns. ([source](https://regexp.dev/guide/usage))
- [Type-Safe Capture Generators](https://awesome-repositories.com/f/development-tools-productivity/type-safe-binding-generators/type-safe-mapper-generators/type-safe-capture-generators.md) — Automatically derives TypeScript types from named capture groups for compile-time validation of matched data.
- [Regular Expression Converters](https://awesome-repositories.com/f/development-tools-productivity/regular-expression-converters.md) — Converts existing regular expressions into readable builder syntax for easier maintenance and understanding.

### Part of an Awesome List

- [Readable Regex Builders](https://awesome-repositories.com/f/awesome-lists/devtools/regex-and-pattern-matching/regex-pattern-matching/readable-regex-builders.md) — Builds regular expressions by chaining readable method calls instead of writing raw pattern strings. ([source](https://cdn.jsdelivr.net/gh/unjs/magic-regexp@main/README.md))
- [Lookahead and Lookbehind Helpers](https://awesome-repositories.com/f/awesome-lists/devtools/regex-and-pattern-matching/regex-pattern-matching/negative-regex-assertions/lookahead-and-lookbehind-helpers.md) — Provides chainable methods for adding lookahead and lookbehind conditions to regex patterns.
- [Regex Lookaround Assertions](https://awesome-repositories.com/f/awesome-lists/devtools/regex-and-pattern-matching/regex-pattern-matching/negative-regex-assertions/regex-lookaround-assertions.md) — Adds positive or negative lookahead and lookbehind conditions to a pattern using helpers like `after`, `before`, and `notBefore`. ([source](https://regexp.dev/guide/usage))

### Programming Languages & Runtimes

- [Compile-Time Regex Compilation](https://awesome-repositories.com/f/programming-languages-runtimes/compiler-extensions/compile-time-regex-compilation.md) — Transforms readable regex syntax into native RegExp objects during compilation to eliminate runtime overhead.
- [Named Capture Group Generators](https://awesome-repositories.com/f/programming-languages-runtimes/named-capture-group-generators.md) — Automatically derives TypeScript types from named capture groups in regex patterns for compile-time validation.
- [Named Capture Groups](https://awesome-repositories.com/f/programming-languages-runtimes/named-capture-groups.md) — Wraps part of a pattern in a named capture group so the matched value is accessible by name in the result object. ([source](https://regexp.dev/guide/usage))
- [Regex Builder Chains](https://awesome-repositories.com/f/programming-languages-runtimes/programming-utilities/string-utilities/string-manipulators/method-chaining/regex-builder-chains.md) — Builds regular expressions by chaining natural-language methods like `exactly` and `oneOrMore` instead of raw strings.
- [Regex Syntax Converters](https://awesome-repositories.com/f/programming-languages-runtimes/bidirectional-type-conversion/regex-syntax-converters.md) — Provides a bidirectional converter that translates existing RegExp literals into readable builder syntax.

### Software Engineering & Architecture

- [String Literal Match Type Predictions](https://awesome-repositories.com/f/software-engineering-architecture/pattern-matching-libraries/type-aware-matching/compile-time-match-type-prediction/string-literal-match-type-predictions.md) — Derives exact TypeScript types from string literal inputs for compile-time validation of regex matches. ([source](https://regexp.dev/guide/usage))
- [Regex Syntax Tree Compilers](https://awesome-repositories.com/f/software-engineering-architecture/trees/syntax-tree-construction/regex-syntax-tree-compilers.md) — Parses the builder chain into an abstract syntax tree and compiles it to a standard RegExp literal at build time.

### Operating Systems & Systems Programming

- [Regex Lookahead Helpers](https://awesome-repositories.com/f/operating-systems-systems-programming/system-administration-maintenance/file-system-management/file-system-operations/block-allocation-and-fragmentation/lookahead-based-allocators/regex-lookahead-helpers.md) — Ships chainable methods like `after` and `before` for adding lookahead and lookbehind assertions to patterns.

### Web Development

- [Bidirectional Regex Syntax Converters](https://awesome-repositories.com/f/web-development/syntax-transformers/bidirectional-regex-syntax-converters.md) — Translates existing RegExp literals into readable builder syntax and back for easier maintenance.
