Solved

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

Posted on 2012-03-26
4
316 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 74

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 74

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

As most anyone who uses or has come across them can attest to, regular expressions (regex) are a complicated bit of magic. Packed so succinctly within their cryptic syntax lies a great deal of power. It's not the "take over the world" kind of power,…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
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…

747 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

9 Experts available now in Live!

Get 1:1 Help Now