in reply to Re: Replace all characters inbetween
in thread Replace all characters inbetween

Thank you! How about the begin and end of the string? I realised that it does not change these, if present.

Replies are listed 'Best First'.
Re^3: Replace all characters inbetween
by AnomalousMonk (Archbishop) on Jun 05, 2022 at 14:33 UTC

    Do you mean something like this?

    Win8 Strawberry 5.8.9.5 (32) Sun 06/05/2022 10:21:09 C:\@Work\Perl\monks >perl use strict; use warnings; for my $s ( 'AAAAAXXXXXXXAAAXXXXXAXXXXAAAA', 'AXA', 'XXXXXXXAAAXXXXXAXXXX', 'XXXXX', 'XA', 'AX', 'X', 'AAAAA', 'YXY', 'A', '', ) { (my $t = $s) =~ s{ (?<! [^A]) X+ (?! [^A]) } {@{[ 'a' x ($+[0] - $-[0]) ]}}xmsg; print "'$s' \n'$t' \n\n"; } ^Z 'AAAAAXXXXXXXAAAXXXXXAXXXXAAAA' 'AAAAAaaaaaaaAAAaaaaaAaaaaAAAA' 'AXA' 'AaA' 'XXXXXXXAAAXXXXXAXXXX' 'aaaaaaaAAAaaaaaAaaaa' 'XXXXX' 'aaaaa' 'XA' 'aA' 'AX' 'Aa' 'X' 'a' 'AAAAA' 'AAAAA' 'YXY' 'YXY' 'A' 'A' '' ''


    Give a man a fish:  <%-{-{-{-<

Re^3: Replace all characters inbetween
by AnomalousMonk (Archbishop) on Jun 05, 2022 at 13:53 UTC

    What is supposed to happen at the begin and end of the string? Please at least give some examples.


    Give a man a fish:  <%-{-{-{-<

Re^3: Replace all characters inbetween
by Anonymous Monk on Jun 05, 2022 at 18:49 UTC
    How about the begin and end of the string? I realised that it does not change these, if present.

    the problem statement was substitute all occurences of a character (let's call it 'X') that is inbetween two others