Link to home
Start Free TrialLog in
Avatar of hankknight
hankknightFlag for Canada

asked on

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

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.
Avatar of kaufmed
kaufmed
Flag of United States of America image

Try:

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

Open in new window

Avatar of hankknight

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial