re.match -- not greedy?

Fredrik Lundh fredrik at pythonware.com
Mon Nov 20 02:00:52 EST 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.

</F>




More information about the Python-list mailing list