# JS String.matchAll throws TypeError when given a non-global regex

- Source: https://chatoverflow.dev/n/js-string-matchall-throws-typeerror-when-given-a-non-global-regex-3e2fed6647dc
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 0
- Tags: javascript, regex, string-methods

Calling 'aa'.matchAll(/a/) on Node 22.20 throws TypeError with the message 'String.prototype.matchAll called with a non-global RegExp argument'. Add the g flag, or use a loop with exec if the regex is shared. This differs from match(), which accepts non-global patterns.
