A script like this:
line1: $string3 = bacdeabcdefghijklabcdeabcdefghijkl;
line2: $string4 = xxyyzzbatttvv;
line3: print \$1 = $1 [EMAIL PROTECTED],$+[0]}, \$ = $\n
if($string3
=~ /(a|b)*/);
line4: print \$1 = $1 [EMAIL PROTECTED],$+[0]}, \$ = $\n
On Jul 29, Pine Yan said:
line1: $string3 = bacdeabcdefghijklabcdeabcdefghijkl;
line2: $string4 = xxyyzzbatttvv;
line3: print \$1 = $1 [EMAIL PROTECTED],$+[0]}, \$ = $\n
if($string3
=~ /(a|b)*/);
line4: print \$1 = $1 [EMAIL PROTECTED],$+[0]}, \$ = $\n
line1: $string3 = bacdeabcdefghijklabcdeabcdefghijkl;
line2: $string4 = xxyyzzbatttvv;
line3: print \$1 = $1 [EMAIL PROTECTED],$+[0]}, \$ = $\n
if($string3
=~ /(a|b)*/);
line4: print \$1 = $1 [EMAIL PROTECTED],$+[0]}, \$ = $\n
if($string4
=~ //);
$1 = a
On Jul 29, Pine Yan said:
line1: $string3 = bacdeabcdefghijklabcdeabcdefghijkl;
line2: $string4 = xxyyzzbatttvv;
If the regexp says match zero or more of (a or b), why can't we
match an empty string in the first place? What causes (a|b)* to make no
difference from (a|b)+?
Pine Yan wrote:
A script like this:
line1: $string3 = bacdeabcdefghijklabcdeabcdefghijkl;
line2: $string4 = xxyyzzbatttvv;
line3: print \$1 = $1 [EMAIL PROTECTED],$+[0]}, \$ = $\n
if($string3
=~ /(a|b)*/);
line4: print \$1 = $1 [EMAIL PROTECTED],$+[0]}, \$
The regex /[ab]*/ on the string bad matches 'ba' because regexes are
greedy by default. They want to match as MUCH as they can.
BUT regexes also try to find the earliest match in the string. This is
why /[ab]*/ on the string cab matches ''. Because the engine found a
successful match of 0
-
From: Tom Allison [mailto:[EMAIL PROTECTED]
Sent: Friday, July 29, 2005 3:23 PM
To: beginners@perl.org
Subject: Re: regular expression match question
Pine Yan wrote:
A script like this:
line1: $string3 = bacdeabcdefghijklabcdeabcdefghijkl;
line2: $string4 = xxyyzzbatttvv
On Jul 29, Pine Yan said:
line3: print \$1 = $1 [EMAIL PROTECTED],$+[0]}, \$ = $\n
if($string3
=~ /(a|b)*/);
line4: print \$1 = $1 [EMAIL PROTECTED],$+[0]}, \$ = $\n
if($string4
=~ //);
$1 = a @{0,2}, $ = ba
$1 = @{0,0}, $ =
I'll go over it again.
No more questions. :D
Sincerely
Pine
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response