Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Node.js support the String.MatchAll method?

Tags:

regex

node.js

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.

like image 617
KalenGi Avatar asked Apr 15 '19 14:04

KalenGi


People also ask

What does matchAll return?

matchAll() The matchAll() method returns an iterator of all results matching a string against a regular expression, including capturing groups.

What is the regular expression function to match all occurrences of a string?

Using regular expressions in JavaScript. Regular expressions are used with the RegExp methods test() and exec() and with the String methods match() , replace() , search() , and split() . Executes a search for a match in a string. It returns an array of information or null on a mismatch.


2 Answers

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

Check out the compatibility on MDN.

enter image description here

like image 95
Dennis Vash Avatar answered Oct 22 '22 00:10

Dennis Vash


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

like image 15
Pier-Luc Gendreau Avatar answered Oct 21 '22 23:10

Pier-Luc Gendreau