Skip to content

Commit 03c32b9

Browse files
committed
docs(README): match sampling use case
1 parent 5d4b7e2 commit 03c32b9

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

README.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,34 @@ import { RB } from '@gruhn/regex-utils'
3535

3636
## Example Use Cases 💡
3737

38-
### Refactor Regex and Check Equivalence 🔄
38+
### Generate random strings from Regex 📜
39+
40+
```typescript
41+
// Generate 5 random email addresses:
42+
const email = RB(/^[a-z]+@[a-z]+\.[a-z]{2,3}$/)
43+
for (const str of email.sample().take(5)) {
44+
console.log(str)
45+
}
46+
47+
48+
49+
50+
51+
52+
53+
// Generate email addresses, which have exactly 20 characters:
54+
const emailLength20 = email.and(/^.{20}$/)
55+
for (const str of emailLength20.sample().take(5)) {
56+
console.log(str)
57+
}
58+
59+
60+
61+
62+
63+
```
64+
65+
### Refactor Regex then Check Equivalence 🔄
3966

4067
Say we identified a regex in the code base that is prone to
4168
[catastrophic backtracking](https://stackoverflow.com/questions/45463148/fixing-catastrophic-backtracking-in-regular-expression)

0 commit comments

Comments
 (0)