repeatedly invoke a regex on matches in js code example
Example 1: repeatedly invoke a regex on matches in js
let str = '<h1>Hello, world!</h1>';
let regexp = /<(.*?)>/g;
let matchAll = str.matchAll(regexp);
alert(matchAll);
matchAll = Array.from(matchAll);
let firstMatch = matchAll[0];
alert( firstMatch[0] );
alert( firstMatch[1] );
alert( firstMatch.index );
alert( firstMatch.input );
Example 2: repeatedly invoke a regex on matches in js
let str = '<h1>Hello, world!</h1>';
let regexp = /<(.*?)>/g;
let matchAll = str.matchAll(regexp);
alert(matchAll);
matchAll = Array.from(matchAll);
let firstMatch = matchAll[0];
alert( firstMatch[0] );
alert( firstMatch[1] );
alert( firstMatch.index );
alert( firstMatch.input );