How to search replace with regex and keep case as original

JavaScript performance comparison

Test case created


releates to this Stack Overflow:

Preparation code

Benchmark.prototype.setup = function() {
    var s1 = "";

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
using anonymous function callback
var s2 = s1.replace(/abc/ig, function (match) {
  return "#" + match + "#";
using backreferences
var s2 = s1.replace(/(abc)/ig, "#$1#");

You can edit these tests or add even more tests to this page by appending /edit to the URL.

Compare results of other browsers


Comment form temporarily disabled.

Add a comment