下面的资料是google出来的,里面有对string.replace的用法介绍。
http://james.padolsey.com/javascript/regular-expressions-in-javascript-part-2/

解决方案 »

  1.   

    replace(rex,f)第一个是正则的匹配。 第二个f 是将匹配的表达式通过方法f进行操作。以str.replace(/-\D/g,function(match){return match.charAt(1).toUpperCase();}) 为例:1.首先匹配str 中的/-\D/g  -非数字
    2.match.charAt(1).toUpperCase();方法返回 第二个字符并大字。
     <script>
     // String.prototype.replace = function(){alert(2)};  var a = 'aa-a56a-!';
      alert(a.replace(/-\D/g,function(match){return match.charAt(1).toUpperCase();}));
      </script>结果:aaA56a!