OT: regex to find email
narshe at gmail.com
Tue Sep 21 17:29:41 CEST 2004
On Tue, 21 Sep 2004 11:16:45 -0400, Peter Hansen <peter at engcorp.com> wrote:
> Josh Close wrote:
> > I've been trying to find a good regex to parse emails, but haven't
> > found any to my liking. I basically need to have
> > ( r'[a-z0-9\.\-\_]@[a-z0-9\.\-\_]', re.IGNORECASE )
> > but the first part can't start with .-_ and the last part has to have
> > a . in it (first/last being before/after the @).
> Use this instead:
> from email.Utils import parseaddr
The docs say this.
Parse address - which should be the value of some
address-containing field such as To: or Cc: - into its constituent
realname and email address parts. Returns a tuple of that information,
unless the parse fails, in which case a 2-tuple of ('', '') is
I need to find all address in a message, not just in the headers. It
looks like for all these methods you have to specify To: From: CC: etc
(i guess that wouldn't necessarily be headers then).
If I missed something there, let me know, 'cause this would be a lot easier.
More information about the Python-list