Skip to content

Commit

Permalink
Explain that string.matchAll(nonGlobalRegExp) throws
Browse files Browse the repository at this point in the history
  • Loading branch information
mathiasbynens committed Nov 6, 2019
1 parent 0227466 commit c8bf766
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/features/string-matchall.md
Expand Up @@ -83,6 +83,10 @@ for (const match of string.matchAll(regex)) {

The general idea is that you just write a simple `for`-`of` loop, and `String#matchAll` takes care of the rest for you.

:::note
**Note:** As the name implies, `String#matchAll` is meant to iterate through _all_ match objects. As such, it should be used with global regular expressions, i.e. those with the `g` flag set, since any non-global regular expressions would only produce a single match (at most). Calling `matchAll` with a non-global RegExp results in a `TypeError` exception.
:::

## `String.prototype.matchAll` support { #support }

<feature-support chrome="73 /blog/v8-release-73#string.prototype.matchall"
Expand Down

0 comments on commit c8bf766

Please sign in to comment.