Beni açıklayan herkes, neden yerel Regex değişken ve yerel olmayan Regex değişkeninin farklı çıktılara sahip olduğunu açıklayabilir.Regex.test() doğru bir yanlış sıra veriyor mu?
var regex1 = /a|b/g;
function isAB1() {
return regex1.test('a');
}
console.log(isAB1()); // true
console.log(isAB1()); // false
console.log(isAB1()); // true
console.log(isAB1()); // false
function isAB2() {
var regex2 = /a|b/g;
return regex2.test('a');
}
console.log(isAB2()); // true
console.log(isAB2()); // true
console.log(isAB2()); // true
console.log(isAB2()); // true
aynı here için JSFiddle
oluşturduk.
: "Aynı global normal ifade örneğinde birden çok kez çağrılır" önceki eşleşmeyi geç. – Hacketo