14

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,684
  • 4
  • 24
  • 37

3 Answers3

17

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

Check out the compatibility on MDN.

enter image description here

Dennis Vash
  • 42,190
  • 6
  • 81
  • 99
15

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

Pier-Luc Gendreau
  • 12,875
  • 4
  • 58
  • 64
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
  • 9,582
  • 3
  • 45
  • 56
Christopher Janzon
  • 1,019
  • 11
  • 22