Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
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 making s'mores by the fire in the courtyard of the Monastery: (13)
As of 2015-07-30 08:41 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 (270 votes), past polls