Solved

ASP.NET / VB / REGEX: Automatically create links beginning with www at beginning

Posted on 2012-03-27
1
270 Views
Last Modified: 2012-03-27
I use the following code to make links clickable where the link begins with www.

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

Open in new window


The problem is that this becomes clickable links:
zwww.example.com
/www.example.com
>www.example.com

It should ONLY become a clickable link if it starts with www and does not have another charactor (other than whitespace)
0
Comment
Question by:hankknight
1 Comment
 
LVL 35

Accepted Solution

by:
Terry Woods earned 500 total points
ID: 37773742
Try this:
input = RegularExpressions.Regex.Replace(input, "(?<!\S)(\www\.\S+[^\s@,.""']+)", "<a href=""http://$1"">$1</a>")

By the way, the first w in www is backslashed in your pattern, which means it's matching any word character rather than just a literal w. It should probably be:
input = RegularExpressions.Regex.Replace(input, "(?<!\S)(www\.\S+[^\s@,.""']+)", "<a href=""http://$1"">$1</a>")
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

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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…

910 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

20 Experts available now in Live!

Get 1:1 Help Now