matchAll()
let regex = /t(e)(st(\d?))/g; let text = 'test1test2'; let array = [...text.matchAll(regex)]; // Output: ["test1", "e", "st1", "1"] console.log(array[0]); // Output: ["test2", "e", "st2", "2"] console.log(array[1]);
Comments
let regex = /t(e)(st(\d?))/g; let text = 'test1test2'; let array = [...text.matchAll(regex)]; // Output: ["test1", "e", "st1", "1"] console.log(array[0]); // Output: ["test2", "e", "st2", "2"] console.log(array[1]);