How to match where the search started?

MRAB python at
Tue Sep 28 17:07:47 CEST 2010

On 28/09/2010 09:10, Florian Kaufmann wrote:
>> From the documentation:
> 7.2.4. Regular Expression Objects, search(string[, pos[, endpos]])
> ... the '^' pattern character matches at the real beginning of the
> string and at positions just after a newline, but not necessarily at
> the index where the search is to start....
> But I'd like to do just that. In Emacs regexps, I think the closest
> equivalent would be \=. Then I could do something like that, and also
> find directly adjacent matches
> reo = re.compile( r'(\=|...)...' );
> while True
>    mo =,pos)
>    if not mo: break
>    ...
If you want to anchor the regex at the start position 'pos' then use
the 'match' method instead.

More information about the Python-list mailing list