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


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

G'day BrowserUk,

You can use a postponed subexpression replacing [^\k<FQ>]+ with (??{"[^$+{FQ}]+"}). It's flagged as "experimental" - that may affect your choice to use it. Here's my test:

#!/usr/bin/env perl use 5.010; use strict; use warnings; my @test_strings = qw{""" "'" '"' ''' ""' "'' '"" ''"}; my $re = qr{ (?<FQ>"|') (??{ "[^$+{FQ}]+" }) \k<FQ> }x; for (@test_strings) { say "Testing [$_] : ", (/$re/ ? '' : 'no '), 'match.'; }

Output:

$ pm_re_kname_in_charclass.pl Testing ["""] : no match. Testing ["'"] : match. Testing ['"'] : match. Testing ['''] : no match. Testing [""'] : no match. Testing ["''] : no match. Testing ['""] : no match. Testing [''"] : no match.

-- Ken