Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions packages/@rescript/runtime/Js_re.res
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,10 @@ type result
An `array` of the match and captures, the first is the full match and the
remaining are the substring captures.
*/
@deprecated({
reason: "Use `RegExp.Result.matches` instead.",
migrate: RegExp.Result.matches(),
})
@deprecated("Use `RegExp.Result.t` instead.")
external captures: result => array<Js_null_undefined.t<string>> = "%identity"

@deprecated({
reason: "Use `RegExp.Result.matches` instead.",
migrate: RegExp.Result.matches(),
})
@deprecated("Use `RegExp.Result.t` instead.")
external matches: result => array<string> = "%identity"

/** 0-based index of the match in the input string. */
Expand Down
1 change: 1 addition & 0 deletions packages/@rescript/runtime/Stdlib_RegExp.res
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module Result = {
type t = array<option<string>>
@get_index external fullMatch: (t, @as(0) _) => string = ""
@send external matches: (t, @as(1) _) => array<option<string>> = "slice"
@send external captures: (t, @as(1) _) => array<option<string>> = "slice"
@get external index: t => int = "index"
@get external input: t => string = "input"
}
Expand Down
12 changes: 10 additions & 2 deletions packages/@rescript/runtime/Stdlib_RegExp.resi
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module Result: {
external fullMatch: (t, @as(0) _) => string = ""

/**
`matches(regExpResult)` returns all matches for `regExpResult`.
`captures(regExpResult)` returns all capture groups for `regExpResult`.

## Examples
```rescript
Expand All @@ -45,15 +45,23 @@ module Result: {
switch regexp->RegExp.exec("ReScript is pretty cool, right?") {
| None => Console.log("Nope, no match...")
| Some(result) =>
switch result->RegExp.Result.matches->Array.keepSome {
switch result->RegExp.Result.captures->Array.keepSome {
| [firstWord, secondWord] => Console.log2(firstWord, secondWord)
| _ => Console.log("Didn't find exactly two words...")
}
}
```
*/
@send
external captures: (t, @as(1) _) => array<option<string>> = "slice"

@deprecated({
reason: "Use `RegExp.Result.captures` instead.",
migrate: RegExp.Result.captures(),
})
@send
external matches: (t, @as(1) _) => array<option<string>> = "slice"

@get external index: t => int = "index"

/**
Expand Down
Loading