Skip to content

Commit 6212d2b

Browse files
committed
docs: update README
1 parent 4973b07 commit 6212d2b

File tree

1 file changed

+32
-12
lines changed

1 file changed

+32
-12
lines changed

README.md

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,38 @@
11
# Regex Utils
22

33
Zero-dependency TypeScript library for regex intersection, complement and other utilities that go beyond string matching.
4-
These are surprisingly hard to come by for any programming language:
5-
6-
- [`intersection`](https://gruhn.github.io/regex-utils/functions/High-level_API.intersection.html):
7-
Combines multiple `RegExp` into a single `RegExp` that descibes their intersection.
8-
- [`complement`](https://gruhn.github.io/regex-utils/functions/High-level_API.complement.html):
9-
Returns a `RegExp` describes the opposite of the input `RegExp`.
10-
- [`size`](https://gruhn.github.io/regex-utils/functions/High-level_API.size.html):
11-
Returns the number of strings matching the input `RegExp`.
12-
- [`enumerate`](https://gruhn.github.io/regex-utils/functions/High-level_API.enumerate.html):
13-
Returns a stream of strings matching the input `RegExp`.
14-
- [`derivative`](https://gruhn.github.io/regex-utils/functions/High-level_API.derivative.html):
15-
Computes a Brzozowski derivative of the input `RegExp`.
4+
These are surprisingly hard to come by for any programming language.
5+
6+
```typescript
7+
import { intersection, size, enumerate } from '@gruhn/regex-utils'
8+
9+
// `intersection` combines multiple regex into one:
10+
const passwordRegex = intersection(
11+
/^[a-zA-Z0-9]{12,32}$/, // 12-32 alphanumeric characters
12+
/[0-9]/, // at least one number
13+
/[A-Z]/, // at least one upper case letter
14+
/[a-z]/, // at least one lower case letter
15+
)
16+
17+
// `size` to calculates the number of strings matching the regex:
18+
console.log(size(passwordRegex))
19+
// 2301586451429392354821768871006991487961066695735482449920n
20+
21+
// `enumerate` returns a stream of strings matching the regex:
22+
for (const sample of enumerate(passwordRegex).take(10)) {
23+
console.log(sample)
24+
}
25+
// aaaaaaaaaaA0
26+
// aaaaaaaaaa0A
27+
// aaaaaaaaaAA0
28+
// aaaaaaaaaA00
29+
// aaaaaaaaaaA1
30+
// aaaaaaaaa00A
31+
// baaaaaaaaaA0
32+
// AAAAAAAAAA0a
33+
// aaaaaaaaaAA1
34+
// aaaaaaaaaa0B
35+
```
1636

1737
## Installation
1838

0 commit comments

Comments
 (0)