Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2012-03-26
4
Medium Priority
?
325 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 2000 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
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…

972 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