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)+"?

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 a's or b's at the beginning of the string.

--
Jeff "japhy" Pinyan         %  How can we ever be the sold short or
RPI Acacia Brother #734     %  the cheated, we who for every service
http://japhy.perlmonk.org/  %  have long ago been overpaid?
http://www.perlmonks.org/   %    -- Meister Eckhart

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to