What's new about regular epression literals from ECMAScript 5 to ECMAScript3

  • 说明|评论
  • 
    function make_a_matcher( ) { 
    	return /a/gi; 
    } 
    var x = make_a_matcher( ); 
    var y = make_a_matcher( ); 
    // Beware: x and y are the same object! 
    x.lastIndex = 10; 
    document.writeln(y.lastIndex); // 10 in ECMAScript 3(FF3.6), & 0 in ECMAScript 5(IE6-9,FF4.0,Chrome,Sfari)
    
    
    
    
    var my_regexp = /([8/5+4]*).{3}/g;
    var str = '8/5+4 is what!';
    
    var result = my_regexp.exec(str); // the same in IE6-9,FF3.6-4.0,Chrome,Safari
    
    for(var i = 0,n = result.length; i < n; ++i){
      document.writeln(result[i]);  
    }