+ 1

What is the difference between greedy and non-greedy matching in Regular expression?

Regular expression

3rd Aug 2016, 7:17 AM
Mool Chand Goyal
Mool Chand Goyal - avatar
2 Réponses
0
Greedy mode tries to match the longest possible term first and non-greedy tries to match the shortest possible term first.
3rd Aug 2016, 8:31 AM
Ali Rabiee
Ali Rabiee - avatar
0
lets take following example : Mool Chand is a good human being. Mool Chand always pays tax. Mool Chand is learning Python. non greedy : ".*?" for ex : Mool Chand.*? Mool Chand only pass string up to starting of second statement. Where as greedy : ".*" Mool Chand .* Mool Chand pass string up to thrid statement.
3rd Aug 2016, 6:01 PM
Pradeep Bilaiya
Pradeep Bilaiya - avatar