Skip to content

Update Js.String[2].match_ return type #559

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from 1 commit
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
Prev Previous commit
fixup! Update Js.String[2].match_ return type
  • Loading branch information
weakish committed Sep 18, 2022
commit dec5b5fb66e36d410f0cd6e9645210871a4e4a4d
11 changes: 5 additions & 6 deletions pages/docs/manual/latest/api/js/string-2.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -318,21 +318,20 @@ Js.String2.localeCompare("CAT", "cat") > 0.0
let match_: (t, Js_re.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:
`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:
- 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. 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([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.") ==
Js.String2.match_("The better bats", %re("/b[aeiou]t/")) == Some([Some("bet")])
Js.String2.match_("The better bats", %re("/b[aeiou]t/g")) == Some([Some("bet"), Some("bat")])
Js.String2.match_("Today is 2018-04-05.", %re("/(\d+)-(\d+)-(\d+)/")) ==
Some([Some("2018-04-05"), Some("2018"), Some("04"), Some("05")])
Js.String.match_(%re("/b[aeiou]g/"), "The large container.") == None
Js.String2.match_("The large container.", %re("/b[aeiou]g/")) == None
```


## normalize

```res sig
Expand Down