Connecting Tech Pros Worldwide Forums | Help | Site Map

reg expression help needed

worzel
Guest
 
Posts: n/a
#1: Nov 22 '05
Hi All,

I am looking for a reg ex that will match email addresses withing <a
href=mailto blah > links.

Actually, I already crafted my own, but with a slight problem:

<a href="mailto:fred@blah.com"> emal me</a> woud be matched as expected, but
so will:

<a href="mailto:fred@blah.com"> emal me</a></td></tr> (table code also
captured)

I think this has something to do with greediness?

Any help much appreciated. As would a link to a site with tons of pre
crafted reg exs!




John Kn [MS]
Guest
 
Posts: n/a
#2: Nov 22 '05

re: reg expression help needed


Worzel,

This regex will capture the email address from the href only:


public static Regex regex = new Regex(
@"([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\."
+ @")|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})",
RegexOptions.IgnoreCase
| RegexOptions.CultureInvariant
| RegexOptions.IgnorePatternWhitespace
| RegexOptions.Compiled
);

This is rather standard:
([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-
]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})

Please get back to me and tell how it works for you.

Thanks,
--------------------[color=blue]
>From: "worzel" <asda@sdarta.com>
>Newsgroups: microsoft.public.dotnet.general
>Subject: reg expression help needed
>Date: Sat, 24 Sep 2005 10:15:08 +0800
>X-Priority: 3
>X-MSMail-Priority: Normal
>X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
>X-RFC2646: Format=Flowed; Original
>X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
>Lines: 20
>Message-ID: <4334b6a9$0$25159$5a62ac22@per-qv1-newsreader-01.iinet.net.au>
>NNTP-Posting-Host: 203.59.171.132
>X-Trace: 1127528106 per-qv1-newsreader-01.iinet.net.au 25159 203.59.171.132
>Path:[/color]
TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfee d00.sul.t-online.de!t-onli
ne.de!news.glorb.com!nntp.waia.asn.au!203.59.27.18 6.MISMATCH!newsfeed.iinet.
net.au!newsfeed.iinet.net.au!per-qv1-newsstorage1.iinet.net.au!per-qv1-newss
torage1.iinet.net.au!per-qv1-newsreader-01.iinet.net.au!not-for-mail[color=blue]
>Xref: TK2MSFTNGXA01.phx.gbl microsoft.public.dotnet.general:50595
>X-Tomcat-NG: microsoft.public.dotnet.general
>
>Hi All,
>
>I am looking for a reg ex that will match email addresses withing <a
>href=mailto blah > links.
>
>Actually, I already crafted my own, but with a slight problem:
>
><a href="mailto:fred@blah.com"> emal me</a> woud be matched as expected,[/color]
but[color=blue]
>so will:
>
><a href="mailto:fred@blah.com"> emal me</a></td></tr> (table code also
>captured)
>
>I think this has something to do with greediness?
>
>Any help much appreciated. As would a link to a site with tons of pre
>crafted reg exs!
>
>
>
>[/color]

{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl {\f0\fnil\fprq2\fcharset0
MS Sans Serif;}{\f1\fswiss\fcharset0 Arial;}}
{\*\generator Msftedit 5.41.21.2500;}\viewkind4\uc1\pard\f0\fs20 Cheers,\par
\par
johnKn [MS-SDK]\par
\par
\par
\par
-Please do not send email directly to this alias. This alias is for \par
newsgroup purposes only\par
\par
-This posting is provided "AS IS" with no warranties, and confers no
rights.\par
\par
-To provide additional feedback about your community experience please send
\par
e-mail to: sdkcomm@microsoft.com\par
\f1\par
}

Closed Thread