Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^2: Determing whether a regexp has capturing matches

by adrianh (Chancellor)
on Feb 27, 2007 at 16:03 UTC ( #602320=note: print w/ replies, xml ) Need Help??


in reply to Re: Determing whether a regexp has capturing matches
in thread Determing whether a regexp has capturing matches

D'oh. Of course. Thanks.

sub has_captured_matches { return $#+ };


Comment on Re^2: Determing whether a regexp has capturing matches
Download Code
Re^3: Determing whether a regexp has capturing matches
by kyle (Abbot) on Feb 27, 2007 at 16:08 UTC

    Keep in mind that $#+ is -1 when the pattern does not match, regardless of whether there are captures.

    "1234" =~ /(1)34/; print $#+, "\n"; "1234" =~ /134/; print $#+, "\n";

    That prints "-1" both times, and -1 is considered a "true" value.

      Keep in mind that $#+ is -1 when the pattern does not match, regardless of whether there are captures.

      Good point. I was just thinking of my context where I'm guaranteed a successful match.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2014-08-30 03:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (291 votes), past polls