Inline regexps and caching

Laurens Holst lholst at
Fri Jan 23 03:34:02 PST 2009


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 + '/' +

var xxx = "MM/dd/yyyy";

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.


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: Backbase employee;

-------------- next part --------------
A non-text attachment was scrubbed...
Name: lholst.vcf
Type: text/x-vcard
Size: 134 bytes
Desc: not available
URL: <>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3265 bytes
Desc: S/MIME Cryptographic Signature
URL: <>

More information about the Es-discuss mailing list