And here's one that also allows left angle bracket to be escaped...
#!/usr/bin/perl # https://perlmonks.org/?node_id=1222687 use strict; use warnings; #use hairy_regex; my $nobacktick = qr/(?:(?:\\.)++|[^\\`]++)*+/s; my $noleftangle = qr/(?:(?:\\.)++|[^\\<]++)*+/s; while( <DATA> ) { s/ \G $nobacktick \K ` $nobacktick ` / $& =~ s! \G $noleftangle \K < !<!gxr /gex; print; } __DATA__ This is `my <string>` that I want to modify because the angle bracket +is between backticks This is `my <string>` that I want to modify because the angle brack +et is between backticks This is `a <string> I don't want to modify because it's not between ba +ckticks This is \`another <left_angle_bracket>`I don't want to modify because +the first backtick is escaped but I do want to modify <the_last_left_ +angle_bracket>` between the backticks `whole string with <string> enclosed in backticks` `whole string with <string> not enclosed in backticks `whole string with <string> not enclosed in backticks\` ``whole string with <string> not enclosed in backticks` `whole string with \<string> enclosed in backticks`
Outputs:
This is `my <string>` that I want to modify because the angle brack +et is between backticks This is `my <string>` that I want to modify because the angle brack +et is between backticks This is `a <string> I don't want to modify because it's not between ba +ckticks This is \`another <left_angle_bracket>`I don't want to modify because +the first backtick is escaped but I do want to modify <the_last_le +ft_angle_bracket>` between the backticks `whole string with <string> enclosed in backticks` `whole string with <string> not enclosed in backticks `whole string with <string> not enclosed in backticks\` ``whole string with <string> not enclosed in backticks` `whole string with \<string> enclosed in backticks`
(more test cases probably required)
In reply to Re: Replacing left angle bracket with HTML entity when between two backtick characters
by tybalt89
in thread Replacing left angle bracket with HTML entity when between two backtick characters
by nysus
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |