Both will match any sequence of one or more characters. The difference is that:
.+
is greedy and consumes as many characters as it can..+?
is reluctant and consumes as few characters as it can.
See Differences Among Greedy, Reluctant, and Possessive Quantifiers in the Java tutorial.
Thus:
e.+d
finds the longest substring that starts withe
and ends withd
(and contains at least one character in between). In your exampleextend cup end
will be found.e.+?d
find the shortest such substring. In your example,extend
andend
are two such non-overlapping matches, so it finds both.