Answers for "repeatedly invoke a regex on matches in js"

0

repeatedly invoke a regex on matches in js

let str = '<h1>Hello, world!</h1>';
let regexp = /<(.*?)>/g;

let matchAll = str.matchAll(regexp);

alert(matchAll); // [object RegExp String Iterator], not array, but an iterable

matchAll = Array.from(matchAll); // array now

let firstMatch = matchAll[0];
alert( firstMatch[0] );  // <h1>
alert( firstMatch[1] );  // h1
alert( firstMatch.index );  // 0
alert( firstMatch.input );  // <h1>Hello, world!</h1>
Posted by: Guest on April-17-2021

Code answers related to "repeatedly invoke a regex on matches in js"

Code answers related to "Javascript"

Browse Popular Code Answers by Language