When I test the code:
let result = 'heymama'.matchAll(/m(a)/g);
I get the error "'heymama'.matchAll is not a function"
When I run the version:
let result = 'heymama'.match(/ma/g);
There's no error.
When I test the code:
let result = 'heymama'.matchAll(/m(a)/g);
I get the error "'heymama'.matchAll is not a function"
When I run the version:
let result = 'heymama'.match(/ma/g);
There's no error.
Before Node 12:
As @dennis-vash alredy pointed out, it's currently not supported in Node.js.
There is this "match-all" npm package alternative though.
const matchAll = require("match-all");
let s = "Hello _World_ and _Mars_";
console.log(matchAll(s, /_([a-z]+)_/gi).toArray());
// => [ "World", "Mars" ]