Come for the quick hacks, stay for the epiphanies. | |
PerlMonks |
(SOLVED) RegEx: backreferences in character classesby LanX (Saint) |
on Oct 24, 2021 at 10:50 UTC ( [id://11137959]=perlquestion: print w/replies, xml ) | Need Help?? |
LanX has asked for the wisdom of the Perl Monks concerning the following question:
Hi I'm failing to use relative backreferences in \g-form in character classes. Please note how [^\1] still works, but [^\g-1] fails. Is there a better syntax within character classes? I'm afraid I need to switch to negated look-aheads or hardcode different quotes.° Debugger demo with perl-de0 The following regex tries to match quoted substrings in $1, the quote in $2
FWIW: \g{-1} instead of \g-1 doesn't help either This question is a follow-up to solution wanted for break-on-spaces (w/specifics)
Cheers Rolf
update°) or using (??{..})
SOLUTIONescaping the dash inside character classes helps, otherwise it's seen as a range
Back to
Seekers of Perl Wisdom
|
|