Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

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

by davido (Cardinal)
on Sep 26, 2013 at 17:05 UTC ( [id://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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (2)
As of 2024-04-19 19:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found