Hi,

I and a colleague were puzzled by some strange behaviour in Firefox, we found that in some browsers literal regular expressions are cached and reused. Testcase:

function test(str) {
   var regexp = /^[^d]*\bd{1,4}\b[^d]*$/g;
   alert('Expexted: 0/true, result: ' +
           regexp.lastIndex + '/' +
           regexp.test(str)
       );
}

var xxx = "MM/dd/yyyy";
test(xxx);
test(xxx);

It turns out that Firefox and Opera return ‘false’ for the second test result, whereas Internet Explorer and Safari return ‘true’ in both cases.

The latter behaviour seems most sensible and expected to me; browsers can of course cache the regular expression object to avoid parsing it over and over again, but they should IMO clone that cached object every time it is used.

~Laurens

--
Note: New email address! Please update your address book.

~~ Ushiko-san! Kimi wa doushite, Ushiko-san nan da!! ~~
Laurens Holst, student, university of Utrecht, the Netherlands
Website: www.grauw.nl. Backbase employee; www.backbase.com

begin:vcard
fn:Laurens Holst
n:Holst;Laurens
email;internet:[email protected]
tel;cell:(+31) 06-41765048
version:2.1
end:vcard

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

_______________________________________________
Es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to