Advertisement
728x90
The matchAll() method can be used to return an iterator of all results matching a string against a regular expression. For example, the below example returns an array of matching string results against a regular expression,
javascript
1let regexp = /Hello(\d?)/g;
2
3let greeting = "Hello1Hello2Hello3";
4
5let greetingList = [...greeting.matchAll(regexp)];
6
7console.log(greetingList[0][0]); //Hello1
8
9console.log(greetingList[1][0]); //Hello2
10
11console.log(greetingList[2][0]); //Hello3Advertisement
Responsive Ad
🎯 Practice NowRelated Challenge
JavaScript Coding Exercise 5
Test your knowledge with this interactive coding challenge.
Start CodingAdvertisement
728x90
348of476