js
regexp.lastIndexبيتصفّر لوحده لما المطابقة تفشل. وده سبب الـbug الشهير: نفس الـregex بيتستخدم في مكانين فالنتايج بتختلف.
البرهان
js
const re = /a/g;
const s = 'aXa';
console.log(re.test(s), re.lastIndex);
console.log(re.test(s), re.lastIndex);
console.log(re.test(s), re.lastIndex);النتيجة
true 1 true 3 false 0