In the code below, I have implemented a regular expression to detect URLs in a string and convert them into hyperlinks:
<body>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
var str = "google.com is here http://www.google.com"
var patt1 = /(\b(?:(https?|ftp):\/\/)?((?:www\d{0,3}\.)?([a-z0-9.-]+\.(?:[a-z]{2,4}|museum|travel)(?:\/[^\/\s]+)*))\b)/g;
var result = str.replace(patt1, function(url) {
return '<a href="' + url + '">' + url + '</a>';
});
alert(result)
document.getElementById("demo").innerHTML = result;
}
</script>
</body>
</html>
The client-side implementation works perfectly. However, when I try to use the same pattern on the server side, it fails to find any matches. Can someone please help me identify what I am doing wrong?
Below is my VB.NET code:
Dim regex As New Regex("/(\b(?:(https?|ftp):\/\/)?((?:www\d{0,3}\.)?([a-z0-9.-]+\.(?:[a-z]{2,4}|museum|travel)(?:\/[^\/\s]+)*))\b)/g;")
Dim mactches As MatchCollection = regex.Matches(strtemp)
For Each match As Match In mactches
strtemp = strtemp.Replace(match.Value, "<a target='_blank' href='" & match.Value & "'>" & match.Value & "</a>")
Next