Greedy And Non Greedy Matching In Python