File tree Expand file tree Collapse file tree 1 file changed +17
-3
lines changed
Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Original file line number Diff line number Diff line change 11# typed-regexp
22A typescript package that strongly restricts types of regular expressions.
33
4- ## Example
4+ ## Examples
5+
6+ As direct dependency: ` npm i typed-regexp `
57``` ts
68import { TypedRegExp } from " typed-regexp" ;
79
810const string = " string to match" ;
911const regexp = new TypedRegExp <[` {${string } ` ],{group: " a" | " b" }>(" (?<group>[ab])({.*)" );
10- /* can also be this:
12+ const match = string .match (regexp );
13+ if (match ) {
14+ const namedGroup = match .groups .group ;
15+ // => "a"|"b"
16+ const group = match [1 ];
17+ // => `{${string}`
18+ }
19+ ```
20+
21+ or as dev dependency: ` npm i -D typed-regexp `
22+ ``` ts
23+ import type { TypedRegExp } from " typed-regexp" ;
24+
25+ const string = " string to match" ;
1126const regexp = / (? <group >[ab ])({.*)/ as TypedRegExp <[` {${string } ` ],{group: " a" | " b" }>;
12- */
1327const match = string .match (regexp );
1428if (match ) {
1529 const namedGroup = match .groups .group ;
You can’t perform that action at this time.
0 commit comments