Test string:
xxxxxxxxxxx
On:
https://regex101.com/
Greedy matches:
x+ = 1 match, 3 steps
x+x+ = 1 match, 4 steps
xx+ = 1 match, 3 steps
(x+)+ = 1 match, 7 steps
(x+x+)+ = 1 match, 7 steps
Nongreedy:
x+ = 11 matches, 23 steps
x+x+ = 5 matches, 15 steps
xx+ = 5 matches, 15 steps
(x+)+ = 11 matches, 46 steps
(x+x+)+ = 5 matches, 25 steps
On web services/sites, if you use nongreedy matching I think you need to be very careful what you do as it might be a possible attack vector for a ddos, by designing some inputs that take hundreds of ms to parse.
Last edited by Gullanian; 03-24-2017 at 03:09 PM.