in reply to Is there any other way to avoid greedy matching
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Is there any other way to avoid greedy matching
by ikegami (Patriarch) on Sep 24, 2007 at 04:33 UTC | |
|
Re^2: Is there any other way to avoid greedy matching
by krissmercedes (Initiate) on Sep 24, 2007 at 03:44 UTC |