re.match -- not greedy?

Fredrik Lundh fredrik at
Mon Nov 20 08:00:52 CET 2006

Carl Banks wrote:

 > I'm suddenly curious if there are any cases at all where greediness
 > changes whether it finds a match.

the "|" operator picks the leftmost subpattern that matches in any way, 
so the *overall* greediness of a Python RE can vary.  e.g.

     re.match("(ab?a|a.a+)", "abaaaaaaaa")

matches three characters, not ten.


More information about the Python-list mailing list