Skip to content

Commit f133f4b

Browse files
committed
2 parents 0a81076 + 534777f commit f133f4b

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# typed-regexp
2+
A typescript package that strongly restricts types of regular expressions.
3+
4+
## Example
5+
```ts
6+
import { TypedRegExp } from "typed-regexp";
7+
8+
const string = "string to match";
9+
const regexp = new TypedRegExp<[`{${string}`],{group:"a"|"b"}>("(?<group>[ab])({.*)");
10+
/* can also be this:
11+
const regexp = /(?<group>[ab])({.*)/ as TypedRegExp<[`{${string}`],{group:"a"|"b"}>;
12+
*/
13+
const match = string.match(regexp);
14+
if (match) {
15+
const namedGroup = match.groups.group;
16+
// => "a"|"b"
17+
const group = match[1];
18+
// => `{${string}`
19+
}
20+
```

0 commit comments

Comments
 (0)