You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
These functions and objects represent available regex constructs.
@@ -30,45 +29,9 @@ Regex syntax: `(...)`.
30
29
31
30
Captures, also known as capturing groups, extract and store parts of the matched string for later use.
32
31
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
35
33
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)+`.
37
35
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
+
:::
73
37
74
-
Allows for matches to be rejected if a specified preceeding pattern is present, without consuming any characters.
Copy file name to clipboardExpand all lines: website/docs/api/types.md
+14-2Lines changed: 14 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,16 +1,28 @@
1
1
---
2
2
id: types
3
3
title: Types
4
-
sidebar_position: 1
5
4
---
6
5
7
6
### `RegexSequence`
8
7
8
+
```ts
9
+
typeRegexSequence=
10
+
|RegexElement[]
11
+
|RegexElement;
12
+
```
13
+
9
14
The sequence of regex elements forming a regular expression. For developer convenience, it also accepts a single element instead of an array.
10
15
11
16
### `RegexElement`
12
17
13
-
Fundamental building blocks of a regular expression, defined as either a regex construct, a string, or a `RegExp` literal (`/.../`).
18
+
```ts
19
+
typeRegexElement=
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.
0 commit comments