+ 1

Lazy RegEx like `??` . I don't get it

After reading this lesson I wondered https://www.sololearn.com/learn/9773/?ref=app If metacharacter `?` is already matching {0, 1} in greedy mode, how will `??` be more lazy than that, by matching {0} ? I was also thinking the same for `{x,}?` but then I thought at least this could act similarly to the `*?` we saw there

6th Sep 2021, 9:44 AM
tebkanlo
tebkanlo - avatar
5 ответов
+ 3
Take a look at this output of the code written in python. You will understand better the difference between greedy and lazy. https://code.sololearn.com/c11peV18VNNe/?ref=app
6th Sep 2021, 7:30 PM
Ugyen Chophel
0
☋g¥☰n☾♄☯Թ♄☰ᒪ That is a great example between lazy and greedy patterns 👍
6th Sep 2021, 7:38 PM
Tim
Tim - avatar
0
Thank you
6th Sep 2021, 7:43 PM
Ugyen Chophel
0
☋g¥☰n☾♄☯Թ♄☰ᒪ thanks, I understood the example given in the lesson. But still I don't see any difference between greedy `?` and lazy `??`, to me they seems to match the same amout, both 0 or 1 , indistinctly
7th Sep 2021, 8:21 AM
tebkanlo
tebkanlo - avatar
0
Mmm... Sadly googling for "lazy regex ?? examples" doesn't match nothing more than simple "add another ? to the quantifier ? to make into non-greedy" I found this website to test it https://regex101.com/r/QZZ0qP/1 And by adding/removing a `? ` I only see the match highlights changing from 27 matches to 35 matches EDIT: By opening the list of matches (menu icon top right) it shows more "empty" match, even between the 0 or 1 letter [ab] . 🤔💭 Paradoxically, I get more results in lazy mode🤔😅
7th Sep 2021, 9:26 AM
tebkanlo
tebkanlo - avatar