I am using JavaScript's replace() function to replace a regular expression matching A-Z, a-z, 0-9, dash (-), underscore (_) and dot (.). I am trying to replace it with part of the matched string with tags around it, but the code I have only replaces the matches with: <b>$1</b>.
Any help, please?
<!DOCTYPE html>
<html>
<body>
<textarea id="demo" rows="10" cols="20">
<table></table>
<b><i>#stock-jsod.20</i>
</b>
</textarea>
<button onclick="testit()">test</button>
<script type="text/javascript">
function testit()
{
var str=document.getElementById("demo").value;
var n = str.replace(/#([A-Za-z0-9_.-]+)/gi, "<b>$0</b>");
document.getElementById("demo").innerHTML=n;
}
</script>
</body>
</html>
My goal here is to replace #stock-jsod.20 with <b>#stock-jsod.20</b>, but currently it only replaces it with <b>$0</b>.
<b></b>around it!