help with parsing email

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Mon Aug 18 06:43:02 EDT 2008


En Thu, 14 Aug 2008 12:50:57 -0300, Ahmed, Shakir <shahmed at sfwmd.gov> escribió:

> I need to grab/parse numeric numbers such as app number from incoming
> emails stored in Microsoft Outlook (Microsoft Exchange server) with
> specified subject line.
>
> The email body is like this
>
> myregion ; tst ; 11-Aug-2008
>
> http://my.xyz.com/dddd/content/ifs/apps/myDocFolder/NoticeOfapplication/080612-21_test_337683.pdf
>
> I need to extract 080612-21_ number from above line from incoming
> emails.

I can't help with the part dealing with Outlook - but once you retrieved the email body, it's easy:

import re
re_number = re.compile(r"NoticeOfapplication/([0-9-_]+)")
match = re_number.search(body)
if match:
  print match.group(1)

(this matches any numbers plus "-" and "_" after the words NoticeOfapplication written exactly that way)

-- 
Gabriel Genellina




More information about the Python-list mailing list