It’s much easier to show the Javascript code than offer a complex explanation:
var html = '<input tabindex="1" type="text">';
html.replace(/tabindex="([0-9]+)"/g, 'tabindex="' + ("$1" * i) + '"');
In this code, “$1” will always be a string, meaning this RegExp will always result in ‘tabindex=”NaN”‘ … Using parseInt doesn’t work.
Is it possible to cast the response from the RegExp as an integer so I can perform maths on the replacement?
The replacement argument can be a function:
However, you should only be using regexps to manipulate HTML if you don’t have a parser. If this code is to run in a browser, then you have a parser. If the node is coming from another document, use
document.importNode. If the node is in the same document, useNode.cloneNode. Both support deep copying.