Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Replacing left angle bracket with HTML entity when between two backtick characters

by tybalt89 (Monsignor)
on Sep 20, 2018 at 09:36 UTC ( [id://1222702]=note: print w/replies, xml ) Need Help??


in reply to Replacing left angle bracket with HTML entity when between two backtick characters

#!/usr/bin/perl # https://perlmonks.org/?node_id=1222687 use strict; use warnings; my $nobacktick = qr/(?:\\.|[^\\`]++)*+/s; while( <DATA> ) { s/ $nobacktick \K ` $nobacktick ` / $& =~ s{<}{&lt;}gr /gex; print; } __DATA__ This is `my <string>` that I want to modify because the angle bracket +is between backticks This is `my &lt;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\`

Outputs:

This is `my &lt;string>` that I want to modify because the angle brack +et is between backticks This is `my &lt;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 &lt;the_last_le +ft_angle_bracket>` between the backticks `whole string with &lt;string> enclosed in backticks` `whole string with <string> not enclosed in backticks `whole string with <string> not enclosed in backticks\`
  • Comment on Re: Replacing left angle bracket with HTML entity when between two backtick characters
  • Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1222702]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2024-04-19 13:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found