[Tutor] Regular Expressions and RFC 822

Sean 'Shaleh' Perry shalehperry@attbi.com
Sun, 19 May 2002 15:15:31 -0700 (PDT)


>> 
>> Can someone help me by showing me an example of how I could do this...
>>
> I don't like regular expressions and I think a lot of people
> agree. You can do this easily without them:
> 

there is another reason than "not liking regular expressions".

RFC822 allows for continuation lines:

SUBJECT: this is my really long long long long long subject line from a galaxy
  far far far far far away

So even if you used a regex to match re.compile(r'(\w+):(.+)') you would still
miss the continuation line.  So you almost need a preprocessor which
concatenates lines if there is a continuation and when the line is finished
parse it.  Look at the rfc822 module for a better approach and to avoid
reinventing the wheel.