develooper Front page | perl.perl6.users | Postings from October 2022

Re: how do I do a literal string in the target of a regex?

Thread Previous | Thread Next
From:
ToddAndMargo via perl6-users
Date:
October 30, 2022 01:03
Subject:
Re: how do I do a literal string in the target of a regex?
Message ID:
a26ef5a5-0ab3-ca6c-dbb0-caa3a31b41e6@zoho.com
On 10/29/22 13:02, ToddAndMargo via perl6-users wrote:
> Hi All,
> 
> I am trying to change
> 
>       /
> 
> into
> 
>       \\\
> 
> This works:
> 
> 
> $ echo "a/b/c/d" | raku -ne 'my $x=$_; $x~~s:g|$(Q[/])|\\\\\\|;print $x 
> ~ "\n"'
> a\\\b\\\c\\\d
> 
> 
> But this does not:
> 
> $ echo "a/b/c/d" | raku -ne 'my $x=$_; $x~~s:g|$(Q[/])|Q[\\\]|;print $x 
> ~ "\n"'
> aQ[\]bQ[\]cQ[\]d
> 
> 
> How do I put a literal string in the
> target of a regex?
> 
> Many thanks,
> -T


The guys on the chat line made me write a
better description and in the process I
figured it out!

$ echo "a/b/c/d" | raku -ne 'my $x=$_; $x~~s:g|$(Q[/])|$(Q[\\\])|;print 
$x ~ "\n"'

a\\\b\\\c\\\d


I forgot the $() in the target!





Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About