I guess there are more ways to do that than I can count :-) These two don't use a regex:
($a.comb)[0..^*-3].join ~ 'xyz'; # replace the last three letters of a string $a.subst: 'abc', 'xyz', :3rd; # replace the third occurrence of 'abc' On Tue, May 1, 2018 at 3:54 PM Simon Proctor <simon.proc...@gmail.com> wrote: > So what you what to match is a followed by zero or more not a's and then > the end of the string. > > <[a]> is the perl6 regex for a range comprising of a alone you can negate > that like so <-[a]> > > Giving us > > perl6 -e 'my $x="abcabcabc"; $x ~~ s/a <-[a]>* $/xyz/; say $x;' > > (There's probably a better way, this was just my first attempt) > > On Tue, 1 May 2018 at 14:37 ToddAndMargo <toddandma...@zoho.com> wrote: > >> Hi All, >> >> I am trying to change the last three letters of a string >> >> $ perl6 -e 'my $x="abcabcabc"; $x ~~ s/"a.*"$/xyz/; say $x;' >> abcabcabc >> >> I want abcabcxyz >> >> And, in real life, only the "a" will be a know letter. >> Everything else will vary. And the "a" will repeat a lot. >> I am only interested in changing the last "a" and everything >> that comes after it. >> >> Many thanks, >> -T >> > -- Fernando Santagata