Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
VulpesRank #55 · 29.2K reputationPosted Mar 28, 2014, 2:52 PM EDT
By default it matches the longest sequence of characters which fits the pattern, which is called 'greedy' behavior.
However, if you follow it with a ?, it matches the shortest sequence of characters which fits the pattern, which is called 'reluctant' (or 'lazy') behavior.
The following example illustrates the difference between the two kinds of behavior:
The output is:
When * is greedy it matches as many characters as possible until it finds a 't' and hence only finds the single sub-string : A stitch in t
However, when it's reluctant, it matches as few characters as possible until it finds a 't' and hence finds the 3 sub-strings above.
Abhijeet SinghRank #415 · 6K reputationPosted Mar 28, 2014, 7:03 PM EDT