Re: need s/ help

2018-05-01 Thread ToddAndMargo

On 05/01/2018 05:19 PM, Brent Laabs wrote:
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


:-)


Re: need s/ help

2018-05-01 Thread Brent Laabs
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  wrote:

> On 05/01/2018 04:29 PM, ToddAndMargo wrote:
>
>> 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


>> 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
> ~~
>


Re: need s/ help

2018-05-01 Thread ToddAndMargo

On 05/01/2018 04:29 PM, ToddAndMargo wrote:
On Tue, 1 May 2018 at 14:37 ToddAndMargo > 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
~~


Re: need s/ help

2018-05-01 Thread ToddAndMargo
On Tue, 1 May 2018 at 14:37 ToddAndMargo > 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


Re: need s/ help

2018-05-01 Thread ToddAndMargo

On 05/01/2018 01:46 PM, Jonathan Scott Duff wrote:

perl6 -e 'my $x="abcabca.*"; $x ~~ s/"a.*"$/xyz/; say $x;'


There is no ".*" in the string  ($x="abcabca.*")


Re: need s/ help

2018-05-01 Thread Jonathan Scott Duff
On Tue, May 1, 2018 at 8:37 AM, ToddAndMargo  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;'
>

The double quotes around your text make it a string literal, so it will
only match the literal string "a.*" at the end of the string.

➤ perl6 -e 'my $x="abcabca.*"; $x ~~ s/"a.*"$/xyz/; say $x;'
abcabcxyz

Another way you could accomplish your goal (other than the ones already
mentioned elsewhere) is to use (.*) at the front of the regex to greedily
match and capture as much as possible until the "a", then match the rest of
the string and replace it with what you matched plus "xyz" ...

➤ perl6 -e 'my $x="abcabcabc"; $x ~~ s/(.*)a.*$/$0xyz/; say $x;'
abcabcxyz

Though, this could copy a significant amount of text depending on the part
of the string before that final "a".  Also, there could be significant
backtracking depending on the part of the string after that final "a".
But, sometimes it's a useful technique, so I mention it.

cheers,

-Scott




> 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
>


Re: need s/ help

2018-05-01 Thread ToddAndMargo
On Tue, 1 May 2018 at 14:37 ToddAndMargo > 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)



Thank you!


Re: need s/ help

2018-05-01 Thread ToddAndMargo
On Tue, May 1, 2018 at 3:54 PM 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)

On Tue, 1 May 2018 at 14:37 ToddAndMargo 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 09:03 AM, Fernando Santagata wrote:

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'



only the "a" will be consistent.  The string could look like
   abcadksavssa234  expected result  abcadksavssxyz
   askfsssalwekjarrsvs  expected result  askfsssalwekjxyz


Re: need s/ help

2018-05-01 Thread Thomas Klausner
Hi!

On Tue, May 01, 2018 at 04:03:24PM +, Fernando Santagata wrote:
> I guess there are more ways to do that than I can count :-)

Which reminds me of http://paris.mongueurs.net/aplusplus.html

Greetings,
domm

-- 
#!/usr/bin/perl  http://domm.plix.at
for(ref bless{},just'another'perl'hacker){s-:+-$"-g&&print$_.$/}


Re: need s/ help

2018-05-01 Thread Fernando Santagata
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 
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  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


Re: need s/ help

2018-05-01 Thread Simon Proctor
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  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
>


need s/ help

2018-05-01 Thread ToddAndMargo

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