regex confusion

Diez B. Roggisch deets_noospaam at web.de
Tue Dec 9 12:14:59 EST 2003


>> This is a bogus regex - a '*' means "zero or more occurences" for the
>> expression to the left. '?' means "zero or one occurence" for the exp to
>> the left.
> 
> Not true.  See http://www.python.org/doc/current/lib/re-syntax.html :
> 
> *?, +?, ??
> The "*", "+", and "?" qualifiers are all greedy; they match as much text
> as possible.  .... Adding "?" after the qualifier makes it perform the
> match in non-greedy or minimal fashion; as few characters as possible will
> be matched. ....

Hmm. But when thats true, what does ".??" then mean - the first ? is not
greedy, so it is  nothing matched at all. The same is true for ".*?", and
".+?" is then equal to "." So what makes this useful? The regex in question
definitely didn't work with it.

Diez




More information about the Python-list mailing list