http://www.perlmonks.org?node_id=1055865


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