Newbie question about the grenadines of regular expressions

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?
Marios Titas [ Mo, 03 Juli 2006 04:17 ] [ ID #1379012 ]

Re: Newbie question about the grenadines of regular expressions

Marios Titas <ggeeoo [at] in.gr> 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
Sherm Pendley [ Mo, 03 Juli 2006 05:47 ] [ ID #1379013 ]
Perl » alt.perl » Newbie question about the grenadines of regular expressions

Vorheriges Thema: Text Alignment
Nächstes Thema: Pls help me in finding solution of two problems