in reply to Re: PCRE: Repeating Subpattens After Intervening Characters
in thread PCRE: Repeating Subpattens After Intervening Characters

Oops. You're looking for PCREmonks, not Perlmonks.
Darn. I knew it was too easy to reply with:
my $regex = qr/(\d\s+foo)/; $some_string =~ /$regex[^\r\n]*$regex/;

-QM
--
Quantum Mechanics: The dreams stuff is made of

Replies are listed 'Best First'.
Re^3: PCRE: Repeating Subpattens After Intervening Characters
by ikegami (Patriarch) on Sep 14, 2005 at 22:15 UTC
    That doesn't capture properly. Fix:
    my $regex = qr/\d\s+foo/; $some_string =~ /($regex)[^\r\n]*($regex)/;

    Also, your solution doesn't scale (if capturing is desired). He can't say, for example, the following while capturing what $regexp matches:

    my $regex = qr/\d\s+foo/; $some_string =~ /(?:$regex[^\r\n]*)*($regex)/;
      I'm confused -- in what sense doesn't it capture properly?
      DB<1> $x = qr/(\d\s+foo)/; DB<2> $y = 'alpha beta 1 foo gamma delta 2 foo epsilon omega'; DB<3> @z = $y =~ /$x[^\r\n]*$x/; DB<4> x @z 0 '1 foo' 1 '2 foo' DB<5>
      However, I can vaguely see problems getting the capturing desired, if it isn't conveniently what happens when trying to scale.

      -QM
      --
      Quantum Mechanics: The dreams stuff is made of

        hum, my test program must have been buggy. I stand corrected.
Re^3: PCRE: Repeating Subpattens After Intervening Characters
by schnarff (Acolyte) on Sep 14, 2005 at 22:05 UTC
    Oh...I didn't realize PCREmonks existed. I'll go ask them. Thanks for being friendly in the meantime. :-)

    Alex