>> 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 @{0,2}, $& = ba >> $1 = @{0,0}, $& = > >The regex says "match zero or more of (a or b)". In string 1, it matches >a 'b' and then an 'a' at the beginning, thus $& = 'ba'. In string 2, it >matches zero characters (because it's allowed to!) at the beginning, thus >$& eq ''.
yeah, I got the idea why $1 has value "a" in this condition, but other question still reamins: 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)+"? Thanks! 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>