Testing for the first few letters of a string

Jean-Paul Calderone exarkun at divmod.com
Thu Aug 7 23:33:40 CEST 2008


On Thu, 07 Aug 2008 23:08:10 +0200, magloca <magloca at mailinater.com> wrote:
>John Machin wrote:
>
>>> import re
>>> template = '^My name is alex'
>>
>> The ^ is redundant.
>
>Didn't the OP want to match only at the beginning of the string?
>

That's why it's "redundant" instead of "incorrect". ;)

re.match = match(pattern, string, flags=0)
    Try to apply the pattern at the *start* of the string, returning
    a match object, or None if no match was found.

Emphasis mine.

Jean-Paul



More information about the Python-list mailing list