[Tutor] Regular Expressions and RFC 822
Erik Price
erikprice@mac.com
Sun, 19 May 2002 21:56:26 -0400
On Sunday, May 19, 2002, at 06:15 PM, Sean 'Shaleh' Perry wrote:
>> 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.
For the record, I really like regular expressions, though I suppose that
some people don't. Perl-compatible regular expression engines can
handle the above situation (and many others) but I imagine it uses some
sort of preprocessor. Python's regex implementation is a little
different than I'm used to, but I still like 'em (especially in my text
editor where I use them all the time to modify my code).
Erik