Regular Expressions...Speed, etc.
tim_one at email.msn.com
Mon May 29 22:48:47 CEST 2000
> First a quick question:
> Is the match() function any different really then having
> search() with a ^ at the begenning of the string?
Yes, although the difference doesn't become clear until you exploit the
optional slicing arguments of compiled regexps:
>>> import re
>>> p = re.compile("^a")
>>> p.search("cba", 2)
>>> p = re.compile("a")
>>> p.match("cba", 2)
<re.MatchObject instance at ead590>
That is, while there is an "a" at index 2 of "cba", and "match" finds it, a
caret does *not* match starting at index 2 (caret means start-of-string, and
may or may not mean more than that depending on "multiline" mode -- using
"match" instead cuts all that magical crap out of the equation).
> Now my real question :)
> Basically, what I want to do is parse an rfc822 header file.. I don't
> want to use rfc822.Message ...
> Are regular expressions any slower really then the current method?
Beats me -- time it and tell us <wink>.
more-interesting-is-whether-they're-equally-correct-ly y'rs - tim
More information about the Python-list