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
Copy file name to clipboardExpand all lines: docs/API.md
+17-3
Original file line number
Diff line number
Diff line change
@@ -63,14 +63,28 @@ Example: `choiceOf("color", "colour")` matches either `color` or `colour` patter
63
63
64
64
```ts
65
65
function capture(
66
-
sequence:RegexSequence
67
-
):Capture
66
+
sequence:RegexSequence,
67
+
options?: {
68
+
name?:string;
69
+
},
70
+
):Capture;
68
71
```
69
72
70
-
Regexsyntax: `(...)`.
73
+
Regex syntax:
74
+
75
+
- `(...)` for capturing groups
76
+
- `(?<name>...)` for named capturing groups
71
77
72
78
Captures, also known as capturing groups, extract and store parts of the matched string for later use.
73
79
80
+
Capture results are available using array-like [`match()` result object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match#using_match).
81
+
82
+
#### Named groups
83
+
84
+
When using `name` options, the group becomes a [named capturing group](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Named_capturing_group) allowing to refer to it using name instead of index.
85
+
86
+
Named capture results are available using [`groups`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match#using_named_capturing_groups) property on `match()` result.
87
+
74
88
> [!NOTE]
75
89
> 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)+`.
0 commit comments