Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

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

by sgifford (Prior)
on May 03, 2004 at 04:56 UTC ( [id://349920]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://349920]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2024-04-23 12:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found