(function ($) {
  $.fn.clone_form_template = function (options) {
    if (!options) {
      options = {};
    }
    return $(this).map(function () {
      return update($(this).clone(), options)[0];
    });
  };

  // updates a template clone according to conventions
  function update($clone, options) {
    var index = new Date().getTime();

    $clone.find('label,input,textarea,select').each(function (i, obj) {
      update_attrs($(obj), index, options);
    });

    return $clone.removeClass('template').show();
  }

  function update_attrs($element, identifier, options) {
    if ($element.attr('id')) {
      $element.attr('id',
        $element.attr('id').replace(/_-?\d+_/, '_' + identifier + '_')
      );
    }
    if ($element.attr('for')) {
      $element.attr('for',
        $element.attr('for').replace(/_-?\d+_/, '_' + identifier + '_')
      );
    }
    if ($element.attr('name')) {
      if (options.copy_values) {
        $element.val($('[name="' + $element.attr('name') + '"]').val());
      }
      $element.attr('name',
        $element.attr('name').replace(/\[-?\d+\]/, '[' + identifier + ']')
      );
    }
  }
}(jQuery));

@@ -9,16 +9,47 @@
 n ($) %7B%0A
+  var DEFAULT_PATTERN = '-1';%0A%0A
   $.fn.c
@@ -82,24 +82,28 @@
 ion (options
+, cb
 ) %7B%0A    if (
@@ -221,16 +221,20 @@
  options
+, cb
 )%5B0%5D;%0A  
@@ -325,32 +325,36 @@
 ($clone, options
+, cb
 ) %7B%0A    var inde
@@ -493,16 +493,20 @@
  options
+, cb
 );%0A    %7D
@@ -613,28 +613,208 @@
 ier, options
+, cb
 ) %7B%0A
+    var pattern = options.pattern %7C%7C DEFAULT_PATTERN,%0A      underscore_pattern = new RegExp('_' + pattern + '_'),%0A      bracket_pattern = new RegExp('%5C%5C%5B' + pattern + '%5C%5C%5D');%0A%0A
     if ($ele
@@ -890,33 +890,42 @@
 d').replace(
-/_-?%5Cd+_/
+underscore_pattern
 , '_' + iden
@@ -1053,17 +1053,26 @@
 ace(
-/_-?%5Cd+_/
+underscore_pattern
 , '_
@@ -1325,19 +1325,23 @@
 ace(
-/%5C%5B-?%5Cd+%5C%5D/
+bracket_pattern
 , '%5B
@@ -1377,16 +1377,94 @@
 ;%0A    %7D%0A
+    if (typeof cb === 'function') %7B%0A      cb.apply($element, $element);%0A    %7D%0A
   %7D%0A%7D(jQ

Allow customizable pattern and callback