This deals with the specific case you present, but I don't think I'm really dealing in a robust way with escaped backticks and escaped escapes. (Aiieee...) And I don't really like capturing stuff then stuffing it back in a replacement. Oh, well... I gotta go to bed now.
c:\@Work\Perl\monks>perl -wMstrict -le
"use 5.010;
;;
use warnings;
use strict;
;;
use Test::More 'no_plan';
use Test::NoWarnings;
;;
my @tests = (
[ 'is `my <string>` that `also <this> one` too',
'is `my &lgt;string>` that `also &lgt;this> one` too',
],
[ 'is `not <this> one', 'is `not <this> one', ],
[ 'is \`my <NO> that `but <this> one` yes',
'is \`my <NO> that `but &lgt;this> one` yes',
],
[ 'is \\\\`my <this> that `but <this> one` no',
'is \\\\`my &lgt;this> that `but <this> one` no',
],
);
;;
VECTOR:
for my $ar_vector (@tests) {
if (not ref $ar_vector) {
note $ar_vector;
next VECTOR;
}
;;
my ($string, $expected) = @$ar_vector;
;;
(my $got = $string) =~ s{
(?<! (?<! \\) \\) ` [^`]* \K < ([^`]* `)
}
{&lgt;$1}xmsg;
;;
is $got, $expected, qq{'$string' -> '$expected'};
}
;;
done_testing;
"
ok 1 - 'is `my <string>` that `also <this> one` too' -> 'is `my &lgt;s
+tring>` that `also &lgt;this> one` too'
ok 2 - 'is `not <this> one' -> 'is `not <this> one'
ok 3 - 'is \`my <NO> that `but <this> one` yes' -> 'is \`my <NO> that
+`but &lgt;this> one` yes'
ok 4 - 'is \\`my <this> that `but <this> one` no' -> 'is \\`my &lgt;th
+is> that `but <this> one` no'
1..4
ok 5 - no warnings
1..5
Give a man a fish: <%-{-{-{-<
|