[Solved] replace href value in dom variable [duplicate]


If i understand you correctly, you need this:

var re = /(#table\d+)|\((\w{1,2})(\))/g; 
var str="<p id="para">&nbsp;demo test&nbsp;demo test&nbsp;demo test&nbsp;demo test&nbsp;demo test&nbsp;demo test&nbsp;demo test&nbsp;demo test&nbsp;demo test&nbsp;demo test&nbsp;demo test&nbsp;demo test&nbsp;demo test&nbsp;demo test&nbsp;demo test&nbsp;demo test&nbsp;demo test&nbsp;demo test&nbsp;demo test&nbsp;demo test&nbsp;demo test&nbsp;demo test&nbsp;demo test&nbsp;demo test&nbsp;demo<a href="#table1(t1)" id="ytD2F">table1</a> test&nbsp;demo test&nbsp;demo test&nbsp;demo test&nbsp;demo test&nbsp;demo <a href="#table2(t2)" id="ytD2F">table2</a>&nbsp;demo test&nbsp;demo test&nbsp;demo test&nbsp;demo test&nbsp;demo test&nbsp;demo test&nbsp;demo test&nbsp;demo test&nbsp;demo test&nbsp;demo test&nbsp;</p>";
var subst="$2"; 

var result = str.replace(re, subst);
console.log(result);

Regex101 demo: https://regex101.com/r/uP6uY7/1

1

solved replace href value in dom variable [duplicate]