On Sat, Sep 15, 2018 at 4:09 AM ToddAndMargo <toddandma...@zoho.com <mailto:toddandma...@zoho.com>> wrote:

    On 09/15/2018 12:42 AM, ToddAndMargo wrote:
     > Hi All,
     >
     > I am truing to use a variable inside a regex.
     >
     > This work (without the variable):
>     $ p6 'my $x="6937-2.2.19882.exe"; if $x ~~ m/ .*? <<:\N**4>> "-"
     > (.*?) ".exe" / {say "yes";}'
     >     yes
     >
     > I want to turn `<<:\N**4>>` into a variable:
     >
     >
     >     $ p6 'my $x="6937-2.2.19882.exe"; my $i="<<:\\N**4>>"; if $x
    ~~ m/
     > .*? $i  "-" (.*?) ".exe" / {say "yes";}else{say "No"}; say "$i";'
     >
     >     No
     >     <<:\N**4>>
     >
     > The double \\ is to get it past bash
     >
     >
     > What am I doing wrong?
     >
     > Many thanks,
     > -T

    never mind.  It got just a bit too goofy.  I switched
    to .contains and sent myself a tag as to when the
    first bunch was a random 4 digit number.


On 09/15/2018 07:34 AM, Brandon Allbery wrote:
> To interpolate a variable as a regex instead of as a string literal, you
> need to wrap it in < >.
>


That was easy.  I am writing this down!   Thank you!

p6 'my $x="6937-2.2.19882.exe"; my $i="6937"; if $x ~~ m/ .*? <$i> "-" (.*?) ".exe" / {say "yes";}else{say "No"}; say "$i";'
yes
6937

$ p6 'my $x="6937-2.2.19882.exe"; my $i="6938"; if $x ~~ m/ .*? <$i> "-" (.*?) ".exe" / {say "yes";}else{say "No"}; say "$i";'
No
6938

p6 'my $x="6937-2.2.19882.exe"; my $i="<<:\\N**4>>"; if $x ~~ m/ .*? <$i> "-" (.*?) ".exe" / {say "yes";}else{say "No"}; say "$i";'
yes
<<:\N**4>>

--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Serious error.
All shortcuts have disappeared.
Screen. Mind. Both are blank.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Reply via email to