Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

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

by BooK (Curate)
on May 03, 2004 at 06:48 UTC ( #349937=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

Ack. I guess spending two days trying to grok yacc and Parse::Yapp led me to choose to do it the hard way. Thanks for a healthy does of simplicity.

Unfortunately, the following regexp break your very good idea:

$regex = qr/foo/; # should return 0

That only means your code needs at least one capture:

sub captures { my $re = shift; return scalar ( @_ = '' =~ /(?:($re))?/ ) - 1; }

This passes my whole test suite, expect for this regexp:

$regex = qr/(?x) # (comment) (?-x) # (capture) (?x) # (comment)/;

Which dies horribly with the message:

Unmatched ( in regex; marked by <-- HERE in m/(?:(( <-- HERE ?-xism:(?x)  # (comment)
            (?-x) # (capture) (?x) # (comment))))?/

So, $regex compiles, but qr/(?:($regex))?/ doesn't? I'm lost.


Comment on Re: Re: Trying to count the captures in a compiled regular expression
Select or Download Code
Re: Re: Re: Trying to count the captures in a compiled regular expression
by hv (Parson) on May 03, 2004 at 08:28 UTC

    expect for this regexp...

    I guess the matching close paren gets commented out in the combined string, though if so I think that's probably a bug: I think we tried it fix it a while back so that a comment in an embedded qr// would not leak out to the enclosing pattern.

    Hugo

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (14)
As of 2015-07-03 12:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (53 votes), past polls