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

Re: Named capture backreferences cannot be used in character classes?

by davido (Archbishop)
on Sep 26, 2013 at 17:05 UTC ( #1055865=note: print w/ replies, xml ) Need Help??


in reply to Named capture backreferences cannot be used in character classes?

If it is only ' and ", you don't necessarily have to capture:

m/(?(?=Z|Y)[Z]|[Y])/

That's unsightly enough that I would probably want to define it as a named subpattern using:

(?(DEFINE) (?<NAME_PAT>....) )

*sigh* I posted too quickly... each alternate pattern would need to be tested individually, I think:

print "Yes" if $string =~ m/(?(?=')'[^']|) (?(?=")"[^"]|)/x;

Update:

And even that simplifies to:

m/(?:'[^']|"[^"])/

...so I'm sure the actual usage must be more complex. :) My apologies. heh.


Dave


Comment on Re: Named capture backreferences cannot be used in character classes?
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (4)
As of 2014-07-26 06:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (175 votes), past polls