/**
 * Created by huangxinghui on 2015/8/28.
 */

var _ = require('underscore');

module.exports = {
    substitute: function (str) {
        if (str == null) return '';

        var rest = Array.prototype.slice(arguments, 1);
        var len = rest.length,
            args, i;

        if (len == 1 && _.isArray(rest[0])) {
            args = rest[0];
            len = args.length;
        }
        else
            args = rest;

        for (i = 0; i < len; i++){
            str = str.replace(new RegExp("\\{"+i+"\\}", "g"), args[i]);
        }

        return str;
    }
};
@@ -439,104 +439,84 @@
     
-for (i = 0; i %3C len; i++)%7B%0A            str = str.replace(new RegExp(%22%5C%5C%7B%22+i+%22%5C%5C%7D%22, %22g%22),
+str = str.replace(/%5C%7B(%5Cd+)%5C%7D/g, function (m, i) %7B%0A            return
  args%5Bi%5D
 );%0A 
@@ -511,18 +511,16 @@
  args%5Bi%5D
-);
 %0A       
@@ -521,16 +521,18 @@
        %7D
+);
 %0A%0A      

change substitue implement