Why re.match()?

kj no.email at please.post
Thu Jul 2 05:49:57 CEST 2009

In <Xns9C3BCA27ABC36duncanbooth at> Duncan Booth <duncan.booth at invalid.invalid> writes:
>So, for example:

>>>> re.compile("c").match("abcdef", 2)
><_sre.SRE_Match object at 0x0000000002C09B90>
>>>> re.compile("^c").search("abcdef", 2)

I find this unconvincing; with re.search alone one could simply

>>> re.compile("^c").search("abcdef"[2:])
<_sre.SRE_Match object at 0x75918>

No need for re.match(), at least as far as your example shows.

Maybe there are times when re.match() is more "convenient" in some
way, but it is awfully Perlish to "multiply language elements" for
the sake of this trifling convenience.


More information about the Python-list mailing list