This is a "further" question re the replies from moritz and Marshall.

And in following their answers, I found it helpful to remember that "greedy" is not the same as "global." While (b*) is greedy, it is not global, /(b*)/g. In other words (I thought) /(b*)/ stops after the first (moritz caught this)failure success , at the start of the string, whereas adding the /g would tell the regex engine to keep on trying until it reaches the end of the string.

Well, that was my second thought.

But, OOOPS,

"abbbbc"=~/(b*)/g && print "Found: $1"; # Found:

Huh?

Well, is this a case where the rules are different in substitution?

my $string1 = "abbbbc"; my $found1 = $string1 =~ s/(b*)/^/g; print "\$string1: $string1, \$found1: $found1"; $found1 is 4 =head after s/// $string: ^a^^c^ At begin of string ...no "b" found | # satisfies "0 or more 'b's" "a" (duh!) | Two "b"(s) found | # likewise; the first and second 'b's ar +e conflated? and again | "c" | no "b" after "c" | =cut

That this code produces two replacements for the string of four 'b's remains a puzzle. Why does this appear (this may be my error) that the regex conflates two 'b's rather than all four?

Enlightenment?
or Coffee?

Update: Wonderful answer below. s/failure/success/ per moritz; italics closed per ssandv.


In reply to Re: Greediness of * vs. greediness of + by ww
in thread Greediness of * vs. greediness of + by rovf

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.