Hello Experts,
I am using a regular expression to replace a url typed in input with an anchor to display the input, I am using the following code, the RegExp works fine but the replace method cannot replace the matched text.Please advise.
I am using a regular expression to replace a url typed in input with an anchor to display the input, I am using the following code, the RegExp works fine but the replace method cannot replace the matched text.Please advise.
Code:
<script>var test_match = /(((\b|^)https?:\/\/)([A-Za-z][^\b]*)+)|(((\b|^)www\.)([A-Za-z][^\b]*)+)/gi
var x="apple [URL unfurl="true"]www.xyz.com";[/URL]
alert(test_match.test(x));
alert(x.replace(test_match,"<a href=\"$1\" title=\"external link\">$1</a>"));
//alert(x);
</script>