I have made a template (of a set of bunch of html tags which it might be textarea or types of inputs) I want to clone the template. I want to rename the 'name' and 'id' attributes of each element just by replacing the number while cloning. I preffer to use regex in order to do that. 

I want to loop through all Html elements and rename the attributes of new elements. e.g.

```
id="extrainfofiles-0-extrainfofile-extra-info-file-type-id"
for="extrainfofiles-0-extrainfofile-extra-info-file-type-id"
name="ExtraInfoFiles[0][ExtraInfoFile][extra_info_file_type_id]"

```

To:

```
id="extrainfofiles--566345634-extrainfofile-extra-info-file-type-id"
for="extrainfofiles--566345634-extrainfofile-extra-info-file-type-id"
name="ExtraInfoFiles[-566345634][ExtraInfoFile][extra_info_file_type_id]"

```

Any help please.

Here is JsFiddle:
<https://jsfiddle.net/isaacrajaei/133ko1un/>