@@ -33,7 +33,7 @@ import { typedRegExp } from 'ts-regexp';
3333```
3434## 🧩 Usage
3535
36- ### Basic Usage
36+ ### Runtime wrapper
3737
3838Import and use ` typedRegExp ` just like the native ` RegExp ` constructor:
3939
@@ -50,7 +50,7 @@ typedRegExp(pattern: string, flags?: string)
5050```
5151> Note: ` typedRegExp ` returns a plain object, ** not** a ` RegExp ` instance.
5252
53- ### Standard RegExp Methods
53+ #### Standard RegExp Methods
5454
5555All standard ` RegExp ` methods work exactly as expected, but with equivalent or improved typing:
5656
@@ -69,7 +69,7 @@ pattern.sticky; // false
6969// ...
7070```
7171
72- ### Regex-first Methods
72+ #### Regex-first Methods
7373
7474Each ` RegExp ` -related ` string.prototype ` method is available as ` ${MethodName}In ` with equivalent or improved typing:
7575
@@ -89,7 +89,7 @@ pattern.searchIn(string); // like string.search(pattern)
8989pattern .splitIn (string ); // like string.split(pattern)
9090```
9191
92- ### Global Flag Methods
92+ #### Global Flag Methods
9393
9494When using the global (` g ` ) flag, additional methods become available:
9595
@@ -101,7 +101,7 @@ pattern.matchAllIn('1973-12-08'); // like string.matchAll(pattern)
101101pattern .replaceAllIn (' 123-456' , ' #' ); // like string.replaceAll(pattern, replacement)
102102```
103103
104- ### Fallback
104+ #### Fallback
105105
106106If you need access to the underlying ` RegExp ` instance:
107107
@@ -110,6 +110,50 @@ const pattern = typedRegExp('\\d+');
110110const nativeRegExp = pattern .regExp ; // Regular RegExp instance
111111```
112112
113+ ### Types
114+
115+ ` ts-regexp ` exposes some useful parsing types:
116+
117+ > Parse<T extends string >
118+ ``` ts
119+ type X = Parse <' (?<a>0)|(?<b>1)' >;
120+ /*
121+ type X = {
122+ captures: [string, string, undefined];
123+ namedCaptures: {
124+ a: string;
125+ b: undefined;
126+ };
127+ } | {
128+ captures: [string, undefined, string];
129+ namedCaptures: {
130+ b: string;
131+ a: undefined;
132+ };
133+ }
134+ */
135+ ```
136+ > ParseCaptures<T extends string >
137+ ``` ts
138+ type X = ParseCaptures <' (?<a>0)|(?<b>1)' >;
139+ /*
140+ type X = [string, string, undefined] | [string, undefined, string]
141+ */
142+ ```
143+ > ParseNamedCaptures<T extends string >
144+ ``` ts
145+ type X = ParseNamedCaptures <' (?<a>0)|(?<b>1)' >;
146+ /*
147+ type X = {
148+ a: string;
149+ b: undefined;
150+ } | {
151+ b: string;
152+ a: undefined;
153+ }
154+ */
155+ ```
156+
113157## ✨ Features
114158- Strictly typed named & unnamed capture groups
115159- Supports contextual awareness
0 commit comments