Skip to content

Commit 1b4e445

Browse files
Update README.md
1 parent a2bc6cd commit 1b4e445

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

README.md

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,29 @@
11
# TS Regex Builder
22

3-
TypeScript adaptation of Swift Regex Builder API.
3+
User-friendly egular Expression builder for TypeScript and JavaScript.
4+
5+
## The problem & solution
6+
7+
Regular expressions are a powerful tool for matching complex text patterns, yet they are notorious for their hard-to-understand syntax.
8+
9+
Inspired by Swift's Regex Builder, this library allows users to write easily and understand regular expressions.
10+
11+
```ts
12+
// Before
13+
const hexColor = /^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/;
14+
15+
// After
16+
const hexDigit = characterClass(['a', 'f'], ['A', 'F'], ['0', '9']);
17+
const hexColor = buildRegex(
18+
startOfString,
19+
'#',
20+
choiceOf(
21+
repeat({ count: 6 }, hexDigit),
22+
repeat({ count: 3 }, hexDigit),
23+
),
24+
endOfString,
25+
);
26+
```
427

528
## Installation
629

@@ -14,7 +37,7 @@ npm install ts-regex-builder
1437
import { buildRegex, oneOrMore } from 'ts-regex-builder';
1538

1639
// /(Hello)+ World/
17-
const regex = buildRegex(oneOrMore('Hello '), 'World');
40+
const regex = buildRegex(oneOrMore('Hello'), ' World');
1841
```
1942

2043
## Contributing

0 commit comments

Comments
 (0)