Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^3: Regex result being defined when it shouldn't be(?)

by AnomalousMonk (Archbishop)
on Nov 14, 2017 at 19:00 UTC ( [id://1203417]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Regex result being defined when it shouldn't be(?)
in thread Regex result being defined when it shouldn't be(?)

((this)?|(that)?|(third_thing)?)
...
... I don't even trust it. ... there's probably 4 capture groups created as a result.

Just as an aside, the  (?|(pat)|(te)|(rn)) "branch reset" pattern introduced with Perl version 5.10 will suppress the creation of a slew of captures in a case like this:

c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "my $s = 'apathetic'; ;; my @captures = $s =~ m{ (pat) | (te) | (rn) }xms; dd \@captures; ;; @captures = $s =~ m{ (?| (pat) | (te) | (rn)) }xms; dd \@captures; " ["pat", undef, undef] ["pat"]
See Extended Patterns in perlre.


Give a man a fish:  <%-{-{-{-<

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2025-11-13 03:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (68 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.