Solved

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

Posted on 2012-03-26
4
321 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

710 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