in reply to Re: Grab "as many occurrences as there are" in a long string
in thread Grab "as many occurrences as there are" in a long string

Now... that is “Regexp Voodoo!”  :-D

“Surely, I am standing in the presence of a Greater Perl Being,™” he said humbly.

I was thinking about the “greedy” modifier, and how one would need to use this to avoid simply matching the entire string in a case like the one you have cited.   I am quite befuddled by the incantation you have so wisely uttered here.   Where can I perldoc to read more about such Higher Magick, that I may one day Impress My Friends, too?

Replies are listed 'Best First'.
Re^3: Grab "as many occurrences as there are" in a long string
by JavaFan (Canon) on Sep 24, 2010 at 13:39 UTC
    I was thinking about the “greedy” modifier, and how one would need to use this to avoid simply matching the entire string in a case like the one you have cited.
    Ah, you mean as in "something equals /.*?/"? Then here's a question for you. How many times does "FOO.*?BAR" occur in "zero FOO one FOO two BAR three BAR four"?
    Where can I perldoc to read more about such Higher Magick, that I may one day Impress My Friends, too?
    Except for say, all will be revealed by reading man perlre. (Oh, and if you replace "(*FAIL)" with "(?!)", you could have done the trick ever since 5.005 - it's not something from this century).

    Note also that

    /(FOO.*?BAR)(??{ say $1 })(*FAIL)/;
    and
    /(FOO.*BAR)(??{ say $1 })(*FAIL)/;
    print exactly the same matches, although in a possible different order.