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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Named capture backreferences cannot be used in character classes?
by BrowserUk (Patriarch) on Sep 27, 2013 at 06:01 UTC | |
by yitzchak (Sexton) on Sep 30, 2013 at 03:06 UTC | |
by Anonymous Monk on Sep 30, 2013 at 07:05 UTC | |
by BrowserUk (Patriarch) on Sep 30, 2013 at 08:45 UTC | |
by kcott (Archbishop) on Sep 27, 2013 at 13:09 UTC | |
by BrowserUk (Patriarch) on Sep 27, 2013 at 13:43 UTC |