Closed lamyergeier closed 6 years ago
Non-greedy means that if they are multiple ways it can match, it will consume fewer characters rather than more characters. This usually only makes a difference when you're using captures, because otherwise you don't care how it matches.
Example (where +?
is the non-greedy version of +
):
aaab
(a+)(.+)
will return the groups aaa
and b
+
"greedily ate" all the a
(a+?)(.+)
will return the groups a
and aab
+
only ate one a
How 0 or 1 is different from 0 or 1, (non-greedy) ?