Say i have/\d\d/ or /\d{2}/ are not greedy matches; they can only match two consecutive digit characters, so by definition they already correspond with the minimum possible length for permissible matches.This will be a greedy match. How can i avoid it??$num = "423"; if i use if((\d\d)) { };
Perhaps you misunderstand greediness. What exactly are you trying to achieve?
Update:
An example of a pattern where greediness causes the pattern not to match is:
/(.*)(\d)/
In that example, the \d will never match because .* will already have consumed the input. To make it non-greedy use
/(.*?)(\d)/
Update 2: Thanks ikegami, I seem to be really smoking some crack today. :-)
-David
In reply to Re: Is there any other way to avoid greedy matching
by erroneousBollock
in thread Is there any other way to avoid greedy matching
by krissmercedes
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |