How to search replace with regex and keep case as original

JavaScript performance comparison

Test case created

Info

releates to this Stack Overflow:

http://stackoverflow.com/questions/13721758/how-to-search-replace-with-regex-and-keep-case-as-original-in-javascript

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var s1 = "abC...ABc..aBC....abc...ABC";
};
</script>

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 + "#";
});
pending…
using backreferences
var s2 = s1.replace(/(abc)/ig, "#$1#");
pending…

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

Compare results of other browsers

0 comments

Add a comment