Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^2: Elegant way to escape a string in a regex

by Anonymous Monk
on Apr 15, 2025 at 19:44 UTC ( [id://11164719]=note: print w/replies, xml ) Need Help??


in reply to Re: Elegant way to escape a string in a regex
in thread Elegant way to escape a string in a regex

The only way I can think of is with using index() to find the position of the string to replace:

my $template = 'aaa <%xx%> bbb'; my $repl = substr $template, index($template, '<%xx%>'), length('<%xx% +>'), '//div[@id="abc"]'; print $template; # aaa //div[@id="abc"] bbb

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2025-05-22 06:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.