Re: Removing ' characters

2022-01-10 Thread ToddAndMargo via perl6-users

On 1/10/22 07:41, Richard Hainsworth wrote:
If a string is enclosed in ' characters, and I want to remove the 
bracketing ', how do I do it?


Seems like ' is not a normal character, or is it because its not a 
bracketing character?


Using REPL I got

 > my $s = '\'\''
''
 > $s.subst( / \' ~ \' (.+) /, $0)
Use of Nil in string context
   in block  at  line 1

 > my $t = '{}'
{}
 > $t.subst( / \{ ~ \} (.+) /, $0)



For clarity

raku -v

Welcome to Rakudo™ v2021.12.
Implementing the Raku® Programming Language v6.d.
Built on MoarVM version 2021.12.




Hi Richard,

Are you trying to remove "all" single quotes
or just the ones surrounding the spoken word:

The profession said "The prime minister
rejected the phrase 'Bob's your Uncle'".

Which or all of the single quotes?

-T

Bob is definitely NOT my uncle.




Re: Removing ' characters

2022-01-10 Thread William Michels via perl6-users
Hi Richard,

In a script:

my $s = '\'\'';

$s.subst( / "'" ~ "'" (.+) /, {$0}).put;
put s/  \< .+ \/ \> /$// given $s;
put s/ \' <( .+ )> \' /$// given $s;

#all three return:


HTH, Bill.


On Mon, Jan 10, 2022 at 8:46 AM Simon Proctor  wrote:
>
> Within the regex the ' character is just another string so rather than 
> escaping it you can write the regex as :
>
> $s.subst( / "'" ~ "'" (.+) /, $0)
>
> (That's " ' " (without spaces) to be exact.) And it does the trick.
>
> You can do the same when defining it $s = "''"; or $s = 
> q['']; both work.
>
>
> On Mon, 10 Jan 2022 at 16:12, Richard Hainsworth  
> wrote:
>>
>> Aha. Thanks
>>
>> On 10/01/2022 15:59, Gianni Ceccarelli wrote:
>> > On Mon, 10 Jan 2022 15:41:04 +
>> > Richard Hainsworth  wrote:
>> >
>> >> Using REPL I got
>> >>
>> >>   > my $s = '\'\''
>> >> ''
>> >>   > $s.subst( / \' ~ \' (.+) /, $0)
>> >> Use of Nil in string context
>> >> in block  at  line 1
>> > That error message (which is a bit LTA) refers to the `$0`. As
>> > https://docs.raku.org/routine/subst#Callable shows, you need to write:
>> >
>> >  $s.subst( / \' ~ \' (.+) /, { $0 })
>> >
>> >>   > my $t = '{}'
>> >> {}
>> >>   > $t.subst( / \{ ~ \} (.+) /, $0)
>> >> 
>> > This only appear to work because you're running it in the same REPL
>> > session; the previous `subst` had the side-effect of setting `$0`
>> > (well, it sets `$/`, but `$0` is an alias for `$/[0]`…)
>> >
>
>
>
> --
> Simon Proctor
> Cognoscite aliquid novum cotidie
>
> http://www.khanate.co.uk/


Re: Removing ' characters

2022-01-10 Thread Simon Proctor
Within the regex the ' character is just another string so rather than
escaping it you can write the regex as :

$s.subst( / "'" ~ "'" (.+) /, $0)

(That's " ' " (without spaces) to be exact.) And it does the trick.

You can do the same when defining it $s = "''"; or $s =
q['']; both work.


On Mon, 10 Jan 2022 at 16:12, Richard Hainsworth 
wrote:

> Aha. Thanks
>
> On 10/01/2022 15:59, Gianni Ceccarelli wrote:
> > On Mon, 10 Jan 2022 15:41:04 +
> > Richard Hainsworth  wrote:
> >
> >> Using REPL I got
> >>
> >>   > my $s = '\'\''
> >> ''
> >>   > $s.subst( / \' ~ \' (.+) /, $0)
> >> Use of Nil in string context
> >> in block  at  line 1
> > That error message (which is a bit LTA) refers to the `$0`. As
> > https://docs.raku.org/routine/subst#Callable shows, you need to write:
> >
> >  $s.subst( / \' ~ \' (.+) /, { $0 })
> >
> >>   > my $t = '{}'
> >> {}
> >>   > $t.subst( / \{ ~ \} (.+) /, $0)
> >> 
> > This only appear to work because you're running it in the same REPL
> > session; the previous `subst` had the side-effect of setting `$0`
> > (well, it sets `$/`, but `$0` is an alias for `$/[0]`…)
> >
>


-- 
Simon Proctor
Cognoscite aliquid novum cotidie

http://www.khanate.co.uk/


Re: Removing ' characters

2022-01-10 Thread Richard Hainsworth

Aha. Thanks

On 10/01/2022 15:59, Gianni Ceccarelli wrote:

On Mon, 10 Jan 2022 15:41:04 +
Richard Hainsworth  wrote:


Using REPL I got

  > my $s = '\'\''
''
  > $s.subst( / \' ~ \' (.+) /, $0)
Use of Nil in string context
    in block  at  line 1

That error message (which is a bit LTA) refers to the `$0`. As
https://docs.raku.org/routine/subst#Callable shows, you need to write:

 $s.subst( / \' ~ \' (.+) /, { $0 })


  > my $t = '{}'
{}
  > $t.subst( / \{ ~ \} (.+) /, $0)


This only appear to work because you're running it in the same REPL
session; the previous `subst` had the side-effect of setting `$0`
(well, it sets `$/`, but `$0` is an alias for `$/[0]`…)



Re: Removing ' characters

2022-01-10 Thread Gianni Ceccarelli
On Mon, 10 Jan 2022 15:41:04 +
Richard Hainsworth  wrote:

> Using REPL I got
> 
>  > my $s = '\'\''  
> ''
>  > $s.subst( / \' ~ \' (.+) /, $0)  
> Use of Nil in string context
>    in block  at  line 1

That error message (which is a bit LTA) refers to the `$0`. As
https://docs.raku.org/routine/subst#Callable shows, you need to write:

$s.subst( / \' ~ \' (.+) /, { $0 })

>  > my $t = '{}'  
> {}
>  > $t.subst( / \{ ~ \} (.+) /, $0)  
> 

This only appear to work because you're running it in the same REPL
session; the previous `subst` had the side-effect of setting `$0`
(well, it sets `$/`, but `$0` is an alias for `$/[0]`…)

-- 
Dakkar - 
GPG public key fingerprint = A071 E618 DD2C 5901 9574
 6FE2 40EA 9883 7519 3F88
key id = 0x75193F88



Removing ' characters

2022-01-10 Thread Richard Hainsworth
If a string is enclosed in ' characters, and I want to remove the 
bracketing ', how do I do it?


Seems like ' is not a normal character, or is it because its not a 
bracketing character?


Using REPL I got

> my $s = '\'\''
''
> $s.subst( / \' ~ \' (.+) /, $0)
Use of Nil in string context
  in block  at  line 1

> my $t = '{}'
{}
> $t.subst( / \{ ~ \} (.+) /, $0)



For clarity

raku -v

Welcome to Rakudo™ v2021.12.
Implementing the Raku® Programming Language v6.d.
Built on MoarVM version 2021.12.