Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Replace all characters inbetween

by GrandFather (Saint)
on Jun 06, 2022 at 21:55 UTC ( [id://11144463]=note: print w/replies, xml ) Need Help??


in reply to Replace all characters inbetween

Using a simple substitution with look behind and look ahead seems to fit the bill:

use strict; use warnings; my $str = 'XAXAAAAXXXXXXXAAXXXXXAXXXXAAAAX'; my $before = $str; $str =~ s/(?<=A)(X+)(?=A)/'a' x length $1/ge; print "$before\n"; print "$str\n";

Prints:

XAXAAAAXXXXXXXAAXXXXXAXXXXAAAAX XAaAAAAaaaaaaaAAaaaaaAaaaaAAAAX

with lower case 'a' used to make the substitutions clear.

Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-04-25 23:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found