Solved

ASP.NET / VB / REGEX: Automatically Parse http and https Links

Posted on 2012-03-26
1
409 Views
Last Modified: 2012-06-21
Using ASP.NET and VP and REGEX, how can I make links beginning with http:// and https:// HTML links?

http://example.info
should become
<a href="http://example.info">http://example.info</a>

I would like the code below to be modified:

input = RegularExpressions.Regex.Replace(input, VbNewLine, VbNewLine +"<br />")
input = RegularExpressions.Regex.Replace(input, "(\www\.\S+[^\s@,.""']+)", "<a href=""http://$1"">$1</a>")
input = RegularExpressions.Regex.Replace(input, "([^\s@,.""']+\@\S+\.[^\s@,.""']+)", "<a href=""mailto:$1"">$1</a>")
input = RegularExpressions.Regex.Replace(input, "  ", " &nbsp;")
return input

Open in new window

0
Comment
Question by:hankknight
1 Comment
 
LVL 13

Accepted Solution

by:
Carl Bohman earned 500 total points
ID: 37768466
Something like this may work (untested):
input = RegularExpressions.Regex.Replace(input, "(https?://\S+[^\s@,.""']+)", "<a href=""$1"">$1</a>")

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now