Skip to content

Commit f59e6bf

Browse files
docs: improve (#68)
1 parent a666086 commit f59e6bf

File tree

10 files changed

+139
-108
lines changed

10 files changed

+139
-108
lines changed

README.md

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,10 @@ See [Builder API doc](https://callstack.github.io/ts-regex-builder/api/builder)
102102

103103
### Regex Constructs
104104

105-
| Construct | Regex Syntax | Notes |
106-
| ------------------------- | ------------ | ------------------------------------------- |
107-
| `choiceOf(x, y, z)` | `x\|y\|z` | Match one of provided sequences |
108-
| `capture(...)` | `(...)` | Create a capture group |
109-
| `lookahead(...)` | `(?=...)` | Match subsequent text without consuming it |
110-
| `negativeLookhead(...)` | `(?!...)` | Reject subsequent text without consuming it |
111-
| `lookbehind(...)` | `(?<=...)` | Match preceding text without consuming it |
112-
| `negativeLookbehind(...)` | `(?<!...)` | Reject preceding text without consuming it |
105+
| Construct | Regex Syntax | Notes |
106+
| ------------------- | ------------ | ------------------------------- |
107+
| `choiceOf(x, y, z)` | `x\|y\|z` | Match one of provided sequences |
108+
| `capture(...)` | `(...)` | Create a capture group |
113109

114110
See [Constructs API doc](https://callstack.github.io/ts-regex-builder/api/constructs) for more info.
115111

@@ -144,15 +140,20 @@ See [Quantifiers API doc](https://callstack.github.io/ts-regex-builder/api/quant
144140

145141
See [Character Classes API doc](https://callstack.github.io/ts-regex-builder/api/character-classes) for more info.
146142

147-
### Anchors
143+
### Assertions
148144

149-
| Anchor | Regex Syntax | Description |
150-
| --------------- | ------------ | ------------------------------------------------------------------------ |
151-
| `startOfString` | `^` | Match the start of the string (or the start of a line in multiline mode) |
152-
| `endOfString` | `$` | Match the end of the string (or the end of a line in multiline mode) |
153-
| `wordBoundary` | `\b` | Match the start or end of a word without consuming characters |
145+
| Assertion | Regex Syntax | Description |
146+
| ------------------------- | ------------ | ------------------------------------------------------------------------ |
147+
| `startOfString` | `^` | Match the start of the string (or the start of a line in multiline mode) |
148+
| `endOfString` | `$` | Match the end of the string (or the end of a line in multiline mode) |
149+
| `wordBoundary` | `\b` | Match the start or end of a word without consuming characters |
150+
| `lookahead(...)` | `(?=...)` | Match subsequent text without consuming it |
151+
| `negativeLookhead(...)` | `(?!...)` | Reject subsequent text without consuming it |
152+
| `lookbehind(...)` | `(?<=...)` | Match preceding text without consuming it |
153+
| `negativeLookbehind(...)` | `(?<!...)` | Reject preceding text without consuming it |
154154

155-
See [Anchors API doc](https://callstack.github.io/ts-regex-builder/api/anchors) for more info.
155+
156+
See [Assertions API doc](https://callstack.github.io/ts-regex-builder/api/assertions) for more info.
156157

157158
## Examples
158159

website/docs/api/anchors.md

Lines changed: 0 additions & 29 deletions
This file was deleted.

website/docs/api/assertions.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
---
2+
id: assertions
3+
title: Assertions
4+
---
5+
6+
## Anchors
7+
8+
Anchors are special characters or sequences that specify positions in the input string rather than matching specific characters.
9+
10+
### Start and end of string
11+
12+
```ts
13+
const startOfString: Anchor;
14+
const endOfString: Anchor;
15+
```
16+
17+
- `startOfString` anchor matches the start of a string (or line, if multiline mode is enabled). Regex syntax: `^`.
18+
- `endOfString` anchor matches the end of a string (or line, if multiline mode is enabled). Regex syntax: `$`.
19+
20+
### Word boundary
21+
22+
_This API was added in version 1.3.0._
23+
24+
```ts
25+
const wordBoundary: Anchor;
26+
const notWordBoundary: Anchor;
27+
```
28+
29+
- `wordBoundary` matches the positions where a word character is not followed or preceded by another word character, effectively indicating the start or end of a word. Regex syntax: `\b`.
30+
- `notWordBoundary` matches the positions where a word character is followed or preceded by another word character, indicating that it is not at the start or end of a word. Regex syntax: `\B`.
31+
32+
Note: word characters are letters, digits, and underscore (`_`). Other special characters like `#`, `$`, etc are not considered word characters.
33+
34+
## Lookarounds
35+
36+
Lookarounds in regex are used for asserting that some pattern is or isn't followed or preceded by another pattern, without including the latter in the match.
37+
38+
### `lookahead()`
39+
40+
_This API was added in version 1.3.0._
41+
42+
```ts
43+
function lookahead(sequence: RegexSequence): Lookahead;
44+
```
45+
46+
Regex syntax: `(?=...)`.
47+
48+
Allows for conditional matching by checking for subsequent patterns in regexes without consuming them.
49+
50+
### `negativeLookahead()`
51+
52+
_This API was added in version 1.3.0._
53+
54+
```ts
55+
function negativeLookahead(sequence: RegexSequence): NegativeLookahead;
56+
```
57+
58+
Regex syntax: `(?!...)`.
59+
60+
Allows for matches to be rejected if a specified subsequent pattern is present, without consuming any characters.
61+
62+
### `lookbehind()`
63+
64+
_This API was added in version 1.3.0._
65+
66+
```ts
67+
function lookbehind(sequence: RegexSequence): Lookahead;
68+
```
69+
70+
Regex syntax: `(?<=...)`.
71+
72+
Allows for conditional matching by checking for preceeding patterns in regexes without consuming them.
73+
74+
### `negativeLookbehind()`
75+
76+
_This API was added in version 1.3.0._
77+
78+
```ts
79+
function negativeLookahead(sequence: RegexSequence): NegativeLookahead;
80+
```
81+
82+
Regex syntax: `(?<!...)`.
83+
84+
Allows for matches to be rejected if a specified preceeding pattern is present, without consuming any characters.

website/docs/api/builder.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
id: builder
33
title: Builder
4-
sidebar_position: 2
54
---
65

76
### `buildRegExp()`

website/docs/api/character-classes.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
id: character-classes
33
title: Character Classes
4-
sidebar_position: 5
54
---
65

76
Character classes are a set of characters that match any one of the characters in the set.

website/docs/api/constructs.md

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
id: constructs
33
title: Constructs
4-
sidebar_position: 3
54
---
65

76
These functions and objects represent available regex constructs.
@@ -30,45 +29,9 @@ Regex syntax: `(...)`.
3029
3130
Captures, also known as capturing groups, extract and store parts of the matched string for later use.
3231
33-
> [!NOTE]
34-
> TS Regex Builder does not have a construct for non-capturing groups. Such groups are implicitly added when required. E.g., `zeroOrMore(["abc"])` is encoded as `(?:abc)+`.
32+
:::note
3533
36-
### `lookahead()`
34+
TS Regex Builder does not have a construct for non-capturing groups. Such groups are implicitly added when required. E.g., `zeroOrMore("abc")` is encoded as `(?:abc)+`.
3735
38-
```ts
39-
function lookahead(sequence: RegexSequence): Lookahead;
40-
```
41-
42-
Regex syntax: `(?=...)`.
43-
44-
Allows for conditional matching by checking for subsequent patterns in regexes without consuming them.
45-
46-
### `negativeLookahead()`
47-
48-
```ts
49-
function negativeLookahead(sequence: RegexSequence): NegativeLookahead;
50-
```
51-
52-
Regex syntax: `(?!...)`.
53-
54-
Allows for matches to be rejected if a specified subsequent pattern is present, without consuming any characters.
55-
56-
### `lookbehind()`
57-
58-
```ts
59-
function lookbehind(sequence: RegexSequence): Lookahead;
60-
```
61-
62-
Regex syntax: `(?<=...)`.
63-
64-
Allows for conditional matching by checking for preceeding patterns in regexes without consuming them.
65-
66-
### `negativeLookbehind()`
67-
68-
```ts
69-
function negativeLookahead(sequence: RegexSequence): NegativeLookahead;
70-
```
71-
72-
Regex syntax: `(?<!...)`.
36+
:::
7337
74-
Allows for matches to be rejected if a specified preceeding pattern is present, without consuming any characters.

website/docs/api/overview.md

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,18 @@ See [Builder](./api/builder) for more info.
4747

4848
### Regex Constructs
4949

50-
| Construct | Regex Syntax | Notes |
51-
| ------------------------- | ------------ | ------------------------------------------- |
52-
| `choiceOf(x, y, z)` | `x\|y\|z` | Match one of provided sequences |
53-
| `capture(...)` | `(...)` | Create a capture group |
54-
| `lookahead(...)` | `(?=...)` | Match subsequent text without consuming it |
55-
| `negativeLookhead(...)` | `(?!...)` | Reject subsequent text without consuming it |
56-
| `lookbehind(...)` | `(?<=...)` | Match preceding text without consuming it |
57-
| `negativeLookbehind(...)` | `(?<!...)` | Reject preceding text without consuming it |
50+
| Construct | Regex Syntax | Notes |
51+
| ------------------- | ------------ | ------------------------------- |
52+
| `choiceOf(x, y, z)` | `x\|y\|z` | Match one of provided sequences |
53+
| `capture(...)` | `(...)` | Create a capture group |
5854

5955
See [Constructs](./api/constructs) for more info.
6056

61-
> [!NOTE]
62-
> TS Regex Builder does not have a construct for non-capturing groups. Such groups are implicitly added when required.
57+
:::note
58+
59+
TS Regex Builder does not have a construct for non-capturing groups. Such groups are implicitly added when required.
60+
61+
:::
6362

6463
### Quantifiers
6564

@@ -89,12 +88,17 @@ See [Quantifiers](./api/quantifiers) for more info.
8988

9089
See [Character Classes](./api/character-classes) for more info.
9190

92-
### Anchors
91+
### Assertions
92+
93+
| Assertion | Regex Syntax | Description |
94+
| ------------------------- | ------------ | ------------------------------------------------------------------------ |
95+
| `startOfString` | `^` | Match the start of the string (or the start of a line in multiline mode) |
96+
| `endOfString` | `$` | Match the end of the string (or the end of a line in multiline mode) |
97+
| `wordBoundary` | `\b` | Match the start or end of a word without consuming characters |
98+
| `lookahead(...)` | `(?=...)` | Match subsequent text without consuming it |
99+
| `negativeLookhead(...)` | `(?!...)` | Reject subsequent text without consuming it |
100+
| `lookbehind(...)` | `(?<=...)` | Match preceding text without consuming it |
101+
| `negativeLookbehind(...)` | `(?<!...)` | Reject preceding text without consuming it |
93102

94-
| Anchor | Regex Syntax | Description |
95-
| --------------- | ------------ | ------------------------------------------------------------------------ |
96-
| `startOfString` | `^` | Match the start of the string (or the start of a line in multiline mode) |
97-
| `endOfString` | `$` | Match the end of the string (or the end of a line in multiline mode) |
98-
| `wordBoundary` | `\b` | Match the start or end of a word without consuming characters |
99103

100-
See [Anchors](./api/anchors) for more info.
104+
See [Assertions](./api/assertions) for more info.

website/docs/api/quantifiers.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
id: quantifiers
33
title: Quantifiers
4-
sidebar_position: 4
54
---
65

76
Quantifiers in regex define the number of occurrences to match for a pattern.

website/docs/api/types.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,28 @@
11
---
22
id: types
33
title: Types
4-
sidebar_position: 1
54
---
65

76
### `RegexSequence`
87

8+
```ts
9+
type RegexSequence =
10+
| RegexElement[]
11+
| RegexElement;
12+
```
13+
914
The sequence of regex elements forming a regular expression. For developer convenience, it also accepts a single element instead of an array.
1015

1116
### `RegexElement`
1217

13-
Fundamental building blocks of a regular expression, defined as either a regex construct, a string, or a `RegExp` literal (`/.../`).
18+
```ts
19+
type RegexElement =
20+
| RegexConstruct
21+
| RegExp
22+
| string;
23+
```
24+
25+
Regex elements are fundamental building blocks of a regular expression. These can be either further regex constructs, regular strings to be matched literally or `RegExp` literals (`/.../`) for including simple regexes as part of a larger structure.
1426

1527
### `RegexConstruct`
1628

website/sidebars.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default {
3131
'api/constructs',
3232
'api/quantifiers',
3333
'api/character-classes',
34-
'api/anchors',
34+
'api/assertions',
3535
],
3636
},
3737
{
@@ -41,4 +41,3 @@ export default {
4141
},
4242
],
4343
};
44-

0 commit comments

Comments
 (0)