Skip to content

Commit 231471c

Browse files
weakishcristianoc
authored andcommittedSep 18, 2022
Update Js.String[2].match_ return type
`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 #551
1 parent 4e576fb commit 231471c

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed
 

‎pages/docs/manual/latest/api/js/string-2.mdx

+9-8
Original file line numberDiff line numberDiff line change
@@ -315,22 +315,23 @@ Js.String2.localeCompare("CAT", "cat") > 0.0
315315
## match
316316

317317
```res sig
318-
let match_: (t, Js_re.t) => option<array<t>>
318+
let match_: (t, Js_re.t) => option<array<option<t>>>
319319
```
320320

321-
`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:
321+
`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:
322322
- The entire matched string
323323
- Any capture groups if the regexp had parentheses
324-
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.
324+
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.
325325

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

334+
334335
## normalize
335336

336337
```res sig

‎pages/docs/manual/latest/api/js/string.mdx

+5-5
Original file line numberDiff line numberDiff line change
@@ -315,19 +315,19 @@ Js.String.localeCompare("cat", "CAT") > 0.0
315315
## match
316316

317317
```res sig
318-
let match_: (Js_re.t, t) => option<array<t>>
318+
let match_: (Js_re.t, t) => option<array<option<t>>>
319319
```
320320

321321
`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:
322322
- The entire matched string
323323
- Any capture groups if the regexp had parentheses
324-
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.
324+
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.
325325

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

0 commit comments

Comments
 (0)