{"id":14173,"library":"type-level-regexp","title":"Type-Level RegExp","description":"Type-Level RegExp (current version 0.1.17) is a TypeScript library that implements a regular expression parser and matcher entirely at the type level, leveraging TypeScript's template literal types. It allows developers to define regex patterns as string literals and receive compile-time type-safe results when using `String.match()`, `String.matchAll()`, and `String.replace()`. This provides robust validation of regex syntax and strongly typed access to capture groups, significantly reducing runtime errors related to incorrect regex patterns or mismatched group access. The library is currently under active development ('Work In Progress'), implying an iterative release cadence focused on feature expansion and refinement. Its primary differentiator is the deep integration of regex parsing into the TypeScript type system, offering static analysis benefits not typically found in runtime-only regex solutions.","status":"active","version":"0.1.17","language":"javascript","source_language":"en","source_url":"https://github.com/didavid61202/type-level-regexp","tags":["javascript","RegExp","regex","TypeScript","type-level","type-level-programming","typescript"],"install":[{"cmd":"npm install type-level-regexp","lang":"bash","label":"npm"},{"cmd":"yarn add type-level-regexp","lang":"bash","label":"yarn"},{"cmd":"pnpm add type-level-regexp","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Primary function to create a typed RegExp object. Uses ESM imports.","wrong":"const createRegExp = require('type-level-regexp')","symbol":"createRegExp","correct":"import { createRegExp } from 'type-level-regexp'"},{"note":"Utility function for converting the iterator returned by `String.matchAll()` into a typed array.","wrong":"const spreadRegExpIterator = require('type-level-regexp').spreadRegExpIterator","symbol":"spreadRegExpIterator","correct":"import { spreadRegExpIterator } from 'type-level-regexp'"},{"note":"Type-level utility for parsing a RegExp string into its abstract syntax tree (AST). Imported as a type, not a runtime value.","symbol":"ParseRegExp","correct":"import { ParseRegExp } from 'type-level-regexp'"},{"note":"Type-level utility for matching a string against a parsed RegExp AST. Imported as a type, not a runtime value.","symbol":"MatchRegExp","correct":"import { MatchRegExp } from 'type-level-regexp'"}],"quickstart":{"code":"import { createRegExp, spreadRegExpIterator } from 'type-level-regexp'\n\n/** string.match() */\nconst regExp = createRegExp('foO(?<g1>b[a-g]r)(?:BAz|(?<g2>qux))', ['i'])\nconst matchResult = 'prefix foobarbaz suffix'.match(regExp) // matching literal string\nif (matchResult) {\n  console.log(matchResult[0]) // 'foobarbaz'\n  console.log(matchResult[1]) // 'bar'\n  // matchResult[3] // TypeScript error: type '3' can't be used to index type 'RegExpMatchResult<...>' (as shown in README)\n  console.log(matchResult.length) // 3\n  console.log(matchResult.index) // 7\n  console.log(matchResult.groups) // { g1: \"bar\"; g2: undefined; }\n}\n\n/** string.replace() */\nconst regExp2 = createRegExp('(\\\\d{4})[-.](?<month>\\\\w{3,4})[-.](?:\\\\d{1,2})')\nconst replaceResult = '1991-Sept-15'.replace(regExp2, '$<month> $3, $1')\nconsole.log(replaceResult) // 'Sept 15, 1991'\n\n/** string.matchAll() */\nconst regExp3 = createRegExp('c[a-z]{2}', ['g'])\nconst matchALlIterator = 'cat car caw cay caw cay'.matchAll(regExp3)\nconst spreadedResult = spreadRegExpIterator(matchALlIterator)\nconsole.log(spreadedResult[2][0]) // 'caw'\nconsole.log(spreadedResult[3]?.index) // 12","lang":"typescript","description":"Demonstrates how to use `createRegExp` to get strongly typed match results for `String.match()`, `String.replace()`, and `String.matchAll()` against literal strings, including access to capture groups and iterator spreading."},"warnings":[{"fix":"Monitor the GitHub repository for updates and review release notes carefully before upgrading. Pin exact versions for production use and consider using the TypeScript Playground link to test changes.","message":"The library is explicitly marked as 'Work In Progress' (WIP), meaning that APIs and internal implementations are subject to change without strict adherence to semantic versioning for minor updates. Users should expect potential breaking changes in minor or patch releases until a stable major version is released.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"For dynamic string matching, validate runtime results if strict typing is critical, or consider using runtime assertions. If possible, refactor to use literal strings where type-level guarantees are most valuable.","message":"When matching against dynamic (non-literal) strings, the type-level matcher will provide enumerated or less precise types for match results, as the exact match structure cannot be determined at compile-time. Full type-level precision is primarily available when matching against string literals.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Ensure all regular expression patterns passed to `createRegExp` are syntactically valid and correctly formed according to JavaScript RegExp syntax. Utilize online regex testers or the provided TypeScript Playground link for validation during development.","message":"Supplying an invalid regular expression pattern to `createRegExp` will result in a TypeScript compilation error, preventing the code from compiling. This is a deliberate design choice to enforce regex correctness at compile-time, unlike runtime regex engines that would throw a runtime error.","severity":"breaking","affected_versions":">=0.1.0"}],"env_vars":null,"search_vec":"'0.1.17':11 'access':70,86 'activ':92 'allow':36 'analysi':125 'benefit':126 'cadenc':101 'captur':72 'compil':48 'compile-tim':47 'current':9,90 'deep':113 'defin':39 'develop':37,93 'differenti':110 'entir':24 'error':77 'expans':105 'express':20 'featur':104 'focus':102 'found':129 'group':73,85 'implement':17 'impli':97 'incorrect':80 'integr':114 'iter':99 'javascript':136 'level':3,7,28,142,145 'leverag':29 'librari':15,88 'liter':33,44 'matcher':23 'mismatch':84 'offer':123 'pars':117 'parser':21 'pattern':41,82 'primari':109 'program':146 'progress':96 'provid':61 'receiv':46 'reduc':75 'refin':107 'regex':40,65,81,116,134,138 'regexp':4,8,137 'regular':19 'relat':78 'releas':100 'result':53 'robust':62 'runtim':76,132 'runtime-on':131 'safe':52 'signific':74 'solut':135 'static':124 'string':43 'string.match':56 'string.matchall':57 'string.replace':59 'strong':68 'syntax':66 'system':122 'templat':32 'time':49 'type':2,6,27,34,51,69,121,141,144 'type-level':1,5,140 'type-level-program':143 'type-saf':50 'typescript':14,30,120,139,147 'typic':128 'use':55 'valid':63 'version':10 'work':94","created_at":"2026-04-20T01:58:18.637209+00:00","updated_at":"2026-04-20T01:58:18.637209+00:00","problems":[{"fix":"Correct the regular expression string to be syntactically valid (e.g., ensure all opening parentheses have a matching closing parenthesis).","cause":"An invalid regular expression string was passed to the `createRegExp` function.","error":"Argument of type 'string' is not assignable to parameter of type 'RegExpSyntaxError<\"Invalid regular expression, missing closing `)`\">'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/didavid61202/type-level-regexp","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/type-level-regexp","openapi_spec":null,"status_page":null,"smithery":null,"categories":["serialization"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-17","next_check":"2026-07-18","install_tag":null}}