Solved

ASP.NET / VB / REGEX: Automatically create email links ignoring characters at end

Posted on 2012-03-26
4
318 Views
Last Modified: 2012-08-14
I use the following code to make email addresses links.

input = RegularExpressions.Regex.Replace(input, "(\S+\@\S+\.\S+)", "<a href=""mailto:$1"">$1</a>")

Open in new window


The problem is that periods and commas and single quotes and double quotes mess things up.
0
Comment
Question by:hankknight
  • 2
  • 2
4 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 37766509
Try:

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

Open in new window

0
 
LVL 16

Author Comment

by:hankknight
ID: 37767589
kaufmed, that fixes this:
xyz@example.com.
and this:
xyz@example.com"

But not this:
"xyz@example.com"

Could you make it work for both the beginning and the end?

Thanks.
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 37767601
Sure, just replace the thing at the front with the thing I change to on the back. In other words:

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

Open in new window

0
 
LVL 16

Author Comment

by:hankknight
ID: 37870557
0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Do you hate spam? I do, and I am willing to bet you do as well. I often wonder, though, "if people hate spam so much, why do they still post their email addresses on the web?" I'm not talking about a plain-text posting here. I am referring to the fa…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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…

770 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