JS string.replace with Regex [IE 11 vs Chrome]

Let's run on IE 11 and Chrome:

"00".replace( /00/ , ' [$4$0$1] ');


Safe typing:

"00".replace( /00/ , function(){

    return ' [$4$0$1] '

;});


When Regex with "( ... )":

Method 1:

's2s3s4'.replace(/(s)([0-9])/g, '$2$1');

Method 2:

's2s3s4'.replace(/(s)([0-9])/g, function(s1,s2,s3, s4){

    return s3+s2;

});





 

Comments