let str = 'PathofExile \nThe world path of Game';
// match: Reg with/withou `g` flag
let reg = /(path)\s*/ig;
let reg2 = /(path)\s*/i;
let result1 = str.match(reg);
console.log(reg.lastIndex); // 0
// match with global
console.log(result1);
// 0-x: every matched string
console.log(reg.lastIndex); // 0 Reason: reg is the `Formal Parameter`
// match without global
let result2 = str.match(reg2);
console.log(result2);
// 0: whole string 1-x: group match
let result3 = reg.exec(str);
console.log(reg.lastIndex); // 4
let result4 = reg2.exec(str);
console.log(reg.lastIndex); // 0 Explanation: `without` global flag, the lastIndex `always` reset to 0