Here's a possible start on a pure-regex approach (needs Perl version 5.10+ for \K regex operator):
Add more test cases to refine. (In general, see How to ask better questions using Test::More and sample data and Short, Self-Contained, Correct Example.)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', ], ); ;; 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;}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' 1..3 ok 4 - no warnings 1..4
Give a man a fish: <%-{-{-{-<
In reply to Re: Replacing left angle bracket with HTML entity when between two backtick characters
by AnomalousMonk
in thread Replacing left angle bracket with HTML entity when between two backtick characters
by nysus
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |