Re: Newbie question about the grenadines of regular expressions
am 03.07.2006 05:47:26 von Sherm Pendley
Marios Titas writes:
> Regular expressions are supposed to be greedy but when I try to match
> the string "ata" against the regular expression /(t*)/ then the value
> of $1 is the empty string and not "t" (which is the longest match).
> Can someone tell me why?
The * means zero or more matches, so an empty string matches the expression.
That will match at the beginning of the target, and stop there because the
next character is not a "t".
"Greedy" does not mean that the longest match in any position is chosen,
only that the first match found is expanded to the longest possible length
allowed by the regex. For instance, if your target string is "ttaattttt",
then $1 will be "tt", not "ttttt".
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org