in reply to Re: Trying to count the captures in a compiled regular expression
in thread Trying to count the captures in a compiled regular expression

Wow, that works! I knew there had to be a way to evaluate the regexp to get an answer. Good stuff! :)
  • Comment on Re: Re: Trying to count the captures in a compiled regular expression

Replies are listed 'Best First'.
Security Alert: Re: Re: Re: Trying to count the captures in a compiled regular expression
by ysth (Canon) on May 03, 2004 at 06:01 UTC
    Security alert: that will run code in (??{ }) / (?p{ }). Maybe something like this instead?
    $regex = qr:(??{print "look ma, no rm -rf /\n"}):; $captures = (() = ""=~/(|$regex)/) - 1;
    Also, note that you have to add a () set and then subtract it from the count to be able to distinguish between 0 captures and 1 capture.