Skip to content

Commit

Permalink
Update Js.String[2].match_ return type
Browse files Browse the repository at this point in the history
`Js.String2.match_` and `Js.String.match_` return type was changed
in rescript-lang/rescript#5070 and released on 10.0.0.

This commit updates the API documentation.

close rescript-lang#551
  • Loading branch information
weakish committed Sep 18, 2022
1 parent 442b45e commit 388be3e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
17 changes: 9 additions & 8 deletions pages/docs/manual/latest/api/js/string-2.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -315,22 +315,23 @@ Js.String2.localeCompare("CAT", "cat") > 0.0
## match

```res sig
let match_: (t, Js_re.t) => option<array<t>>
let match_: (t, Js_re.t) => option<array<option<t>>>
```

`match(str, regexp)` matches a `string` against the given `regexp`. If there is no match, it returns `None`. For regular expressions without the g modifier, if there is a match, the return value is `Some(array)` where the array contains:
`match(regexp, str)` matches a `string` against the given `regexp`. If there is no match, it returns `None`. For regular expressions without the g modifier, if there is a match, the return value is `Some(array)` where the array contains:
- The entire matched string
- Any capture groups if the regexp had parentheses
For regular expressions with the g modifier, a matched expression returns `Some(array)` with all the matched substrings and no capture groups. See [`String.match`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match) on MDN.
For regular expressions with the g modifier, a matched expression returns `Some(array)` with all the matched substrings and no capture groups. Javscript String.prototype.match can return `undefined` for optional capture groups that are not found, thus the element of the returned array is typed `option<t>`. See [`String.match`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match) on MDN.

```res example
Js.String2.match_("The better bats", %re("/b[aeiou]t/")) == Some(["bet"])
Js.String2.match_("The better bats", %re("/b[aeiou]t/g")) == Some(["bet", "bat"])
Js.String2.match_("Today is 2018-04-05.", %re("/(\d+)-(\d+)-(\d+)/")) ==
Some(["2018-04-05", "2018", "04", "05"])
Js.String2.match_("The large container.", %re("/b[aeiou]g/")) == None
Js.String.match_(%re("/b[aeiou]t/"), "The better bats") == Some([Some("bet")])
Js.String.match_(%re("/b[aeiou]t/g"), "The better bats") == Some([Some("bet"), Some("bat")])
Js.String.match_(%re("/(\d+)-(\d+)-(\d+)/"), "Today is 2018-04-05.") ==
Some([Some("2018-04-05"), Some("2018"), Some("04"), Some("05")])
Js.String.match_(%re("/b[aeiou]g/"), "The large container.") == None
```


## normalize

```res sig
Expand Down
10 changes: 5 additions & 5 deletions pages/docs/manual/latest/api/js/string.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -315,19 +315,19 @@ Js.String.localeCompare("cat", "CAT") > 0.0
## match

```res sig
let match_: (Js_re.t, t) => option<array<t>>
let match_: (Js_re.t, t) => option<array<option<t>>>
```

`match(regexp, str)` matches a `string` against the given `regexp`. If there is no match, it returns `None`. For regular expressions without the g modifier, if there is a match, the return value is `Some(array)` where the array contains:
- The entire matched string
- Any capture groups if the regexp had parentheses
For regular expressions with the g modifier, a matched expression returns `Some(array)` with all the matched substrings and no capture groups. See [`String.match`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match) on MDN.
For regular expressions with the g modifier, a matched expression returns `Some(array)` with all the matched substrings and no capture groups. Javscript String.prototype.match can return `undefined` for optional capture groups that are not found, thus the element of the returned array is typed `option<t>`. See [`String.match`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match) on MDN.

```res example
Js.String.match_(%re("/b[aeiou]t/"), "The better bats") == Some(["bet"])
Js.String.match_(%re("/b[aeiou]t/g"), "The better bats") == Some(["bet", "bat"])
Js.String.match_(%re("/b[aeiou]t/"), "The better bats") == Some([Some("bet")])
Js.String.match_(%re("/b[aeiou]t/g"), "The better bats") == Some([Some("bet"), Some("bat")])
Js.String.match_(%re("/(\d+)-(\d+)-(\d+)/"), "Today is 2018-04-05.") ==
Some(["2018-04-05", "2018", "04", "05"])
Some([Some("2018-04-05"), Some("2018"), Some("04"), Some("05")])
Js.String.match_(%re("/b[aeiou]g/"), "The large container.") == None
```

Expand Down

0 comments on commit 388be3e

Please sign in to comment.