That last one has a special case available, but it's slightly less
portable.  But afaik it works on all platforms we actually support:

> perl6 -e '"screws/nuts/bolts/washers".path.parent.Str.say'
screws/nuts/bolts

On Tue, May 1, 2018 at 4:37 PM, ToddAndMargo <toddandma...@zoho.com> wrote:

> On 05/01/2018 04:29 PM, ToddAndMargo wrote:
>
>> On Tue, 1 May 2018 at 14:37 ToddAndMargo <toddandma...@zoho.com <mailto:
>>>> 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
>>>>
>>>>
>> On 05/01/2018 06:52 AM, Simon Proctor 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)
>>>
>>>
>> Awesome!  Thank you!
>>
>>
>> perl6 -e 'my $x="abc-def-hij"; $x ~~ s/‘-’<-[-]>+$//; say $x;'
>> abc-def
>>
>>
>> $ perl6 -e 'my $x="abc-def-hij"; $x ~~ s|‘-’<-[-]>+$||; say $x;'
>> abc-def
>>
>>
>> $ perl6 -e 'my $x="abc/def/hij"; $x ~~ s|‘/’<-[/]>+$||; say $x;'
>> abc/def
>>
>>
>> $ perl6 -e 'my $x="screws/nuts/bolts/washers"; $x ~~ s|‘/’<-[/]>+$||;
>> say $x;'
>> screws/nuts/bolts
>>
>
>
> `+` means to repeat one or more times; `*` is the same as `+`, except
> it will take a zero times.
>
> $ perl6 -e 'my $x="screws/nuts/bolts/washers"; $x ~~ s|‘/’<-[/]>*$||; say
> $x;'
> screws/nuts/bolts
>
>
>
>
> --
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Computers are like air conditioners.
> They malfunction when you open windows
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>

Reply via email to