[Spambayes] Re: [Spambayes-checkins] spambayes/spambayes message.py, 1.12, 1.13

Skip Montanaro skip at pobox.com
Sun Apr 20 08:57:27 EDT 2003


    Tim> +         #XXX Tim doesn't like this regex.  He will study it to
    Tim> +         #XXX see if he can learn to like it, or come up with
    Tim> +         #XXX something he likes better.  - Tim
    Tim>           return re.sub(r'(?:\r\n|\n|\r(?!\n))', "\r\n", data)

I don't think the negative lookahead assertion is necessary.  By default,
regular expressions are greedy (match the largest possible string), so

    return re.sub(r"\r\n|\n|\r", "\r\n", data)

should work.  Any time \r\n appears, it will be preferred over either \r or
\n, so if the \r branch matches, that implies it wasn't followed by \n.  If
I've been laboring under a misconception for all these years, I'd be happy
to be corrected.

Skip



More information about the Spambayes mailing list