RE Module

Tim Chase python.list at tim.thechases.com
Fri Aug 25 17:29:21 EDT 2006


>> Also, what made the expression greedy?
> 
> They usually are, by default.  It means that when there
> are more than one ways to match the pattern, choose the
> one that matches the most text.  Often there are flags
> available to change that behavior.  I'm not sure off hand
> how to do it with the re module.

In python's RE module, they're like Perl:

Greedy:  "<.*>"
Nongreedy:  "<.*?>"

By appending a question-mark onto the operator, one makes it a 
non-greedy repeat.  It also applies to the plus ("one or more") 
and the questionmark ("zero or one")

-tkc







More information about the Python-list mailing list