Skip to content

Instantly share code, notes, and snippets.

@widoyo
Created November 23, 2012 01:24
Show Gist options
  • Save widoyo/4133590 to your computer and use it in GitHub Desktop.
Save widoyo/4133590 to your computer and use it in GitHub Desktop.
Baca Email RMR
>>> import re
>>> # mencari RMR Number pada Subject email
>>> "Re: RMR Number 121127-I01-07-1".rsplit(" ", 1)[1]
121127-I01-07-1
>>> inputs = ["Re: RMR Number 121127-I01-07-1", "RMR Number 121127-I01-07-1", "Re: RMR NUmber 121127-I08-PP-1"]
>>>
>>> for a in inputs:
... m = re.match(r'.*RMR Number.*(?P<rmr>\d{6}-\w{1}\d{2}-.*-\d{1})', a, re.I)
... if m:
... m.groupdict()['rmr']
...
'121127-I01-07-1'
'121127-I01-07-1'
'121127-I08-PP-1'
>>>
>>> samples_ack = ('> Acknoledgement\t\t: OK',
... '> Acknoledgement\t\t: Ok',
... '> Acknoledgement\t\t: .Ok',
... '> Acknoledgement\t\t: . Ok',
... '> Acknoledgement:Ok',
... 'Acknoledgement : Ok',
... )
>>>
>>> for ack in samples_ack:
... if not re.search('Acknoledgement.*:.*ok', ack, re.I):
... print "GAGAL: %s" % ack
... else:
... print "LULUS: %s" % ack
>>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment