15

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.

KalenGi
  • 1,766
  • 4
  • 25
  • 40

3 Answers3

19

#String.matchAll is supported in Node.js from version 12.0.0

Check out the compatibility on MDN.

enter image description here

Dennis Vash
  • 50,196
  • 9
  • 100
  • 118
15

matchAll is available in Node.js starting from v12.0.0

Pier-Luc Gendreau
  • 13,553
  • 4
  • 58
  • 69
7

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" ]
Lee Goddard
  • 10,680
  • 4
  • 46
  • 63
Christopher Janzon
  • 1,039
  • 11
  • 22