in reply to Pattern matching simultaneous substitution

Your stated requirements have problems:

  1. In isolation, this is pretty straightforward. The following would need some additional "checking" code, but the guts of it are:
    $ perl -E ' my $str = "sssDDDsssDDDssUss"; my ($fore, $aft) = split /U/, $str, 2; $fore =~ s/s/i/g; $aft =~ s/s/o/g; say "$str\n", join "U", $fore, $aft; ' sssDDDsssDDDssUss iiiDDDiiiDDDiiUoo
  2. This makes no sense as there are no more 's' characters left to modify. If there's some typo in what you wrote, then perhaps something similar to the code in my last point would suffice.
  3. This is easily achieved with transliteration:
    $ perl -E ' my $str = "sssDDDsssDDDssUss"; say $str; $str =~ y/DU/M/; say $str; ' sssDDDsssDDDssUss sssMMMsssMMMssMss
  4. You didn't finish writing this point: "... then all s becomes". You'll need to tell us what you intended to write after "becomes".

Some other points:

— Ken

Replies are listed 'Best First'.
Re^2: Pattern matching simultaneous substitution
by Anonymous Monk on Jan 05, 2022 at 20:32 UTC
    Thanks Ken. Re point #2, I put it there, because there can be cases without Ds, but only Us. Therefore there needs to be a conditional on that scenario as well.