On 1/12/25 12:59 AM, William Michels via perl6-users wrote:
~$ /Users/admin/rakudo/rakudo-2024.09/rakudo-moar-2024.09-01-macos- arm64-clang/bin/raku -e '  \
    my Str $AltClickHere = lines[0];  \
    my @AltArray =
       ($AltClickHere ~~ m:g/
           download        #literal
           .*?             #any-character, one-or-more, frugal
          <?before \>  >  #positive look-ahead, match but dont capture \> angle
           /).map(*.Str);   \
    .put for @AltArray;'  todd_test.txt
download='betterbird-128.6.0esr-bb20.de.linux-x86_64.tar.bz2'
download='betterbird-128.6.0esr-bb20.en-US.linux-x86_64.tar.bz2'
download='betterbird-128.6.0esr-bb20.es-AR.linux-x86_64.tar.bz2'

Hi Todd,

Well the previous code I sent works with your example, but the code above is better:

1. The first token can be simplified to the literal `download`. You could use `[ ^ | download ]`, which would capture everything from `^` the beginning of the string regardless of whether-or-not the string starts with `download`.

2. The second token, `.*?`,    matches any-character, one-or-more, frugally.

3. The third (original) token, `<?before \> | \h+ >` could be simplified to either `<?before \> >` or `<?before \h+ >`. It says to find the pattern but stop the match before the literal ">" angle or "\h+" one-or- more horizontal whitespace character.

I hope that helps a bit. Oh yeah, if you want just the quoted download, you could use a positive-lookbehind, `<?after … >`. See below:

~$ /Users/wmichels/rakudo/rakudo-2024.09/rakudo-moar-2024.09-01-macos- arm64-clang/bin/raku -e '  \
    my Str $AltClickHere = lines[0];  \
    my @AltArray =
       ($AltClickHere ~~ m:g/
          <?after download \= >  #positive look-behind, match but dont capture download\=
           .*?                    #any-character, one-or-more, frugal
          <?before \>  >         #positive look-ahead, match but dont capture \> angle
           /).map(*.Str);   \
    .put for @AltArray;'  todd_test.txt
'betterbird-128.6.0esr-bb20.de.linux-x86_64.tar.bz2'
'betterbird-128.6.0esr-bb20.en-US.linux-x86_64.tar.bz2'
'betterbird-128.6.0esr-bb20.es-AR.linux-x86_64.tar.bz2'

HTH, Bill.

On Jan 11, 2025, at 19:09, ToddAndMargo via perl6-users <perl6- us...@perl.org> wrote:

Hi All,

In another post, Bill gave me a wonderful match that took
a ridiculously long line of test and cut out what I wanted
and put it into cells of an array.

@ClickArray = $ClickPage ~~ m:g/ <?before ^ | download > .*? <?before \> | \h+ > /;

I do not understand what he did.

m:g   = match and global

<>    = litteral

?     what does this do?
^     what does this do?

|     what does this do?
\     what does this do

\h+ >   what does this do?



Yours in confusion.
-T


In practice:


[0] > my Str $x=Q{^[[200~download='betterbird-128.6.0esr- bb20.de.linux-x86_64.tar.bz2'>    <div class="img bz2"></div>    <div class="name">        <div class="file fs-1-2 bold">betterbird-128.6.0esr-bb20.de.linux-x86_64.tar.bz2</div> <div class="data upper size fs-0-7"><span class="bold">Size:</span> 80.26<span class="fs-0-8 bold">MB</span></div>        <div class="data upper modified fs-0-7"><span class="bold">Last modified:</span> Tue. January 7th, 2025 - 10:54pm</div>    </div></a></div><div class="block"><a href="LinuxArchive/betterbird-128.6.0esr-bb20.en- US.linux-x86_64.tar.bz2" class="bz2" download='betterbird-128.6.0esr- bb20.en-US.linux-x86_64.tar.bz2'> <div class="img bz2"></div>    <div class="name">        <div class="file fs-1-2 bold">betterbird-128.6.0esr-bb20.en-US.linux-x86_64.tar.bz2</div> <div class="data upper size fs-0-7"><span class="bold">Size:</span> 80.04<span class="fs-0-8 bold">MB</span></div>        <div class="data upper modified fs-0-7"><span class="bold">Last modified:</span> Tue. January 7th, 2025 - 10:42pm</div>    </div>    </a></div><div class="block"><a href="LinuxArchive/betterbird-128.6.0esr-bb20.es- AR.linux-x86_64.tar.bz2" class="bz2" download='betterbird-128.6.0esr- bb20.es-AR.linux-x86_64.tar.bz2'> <div class="img bz2"></div>    <div class="name">        <div class="file fs-1-2 bold">betterbird-128.6.0esr-bb20.es-AR.linux-x86_64.tar.bz2</div>} download='betterbird-128.6.0esr-bb20.de.linux-x86_64.tar.bz2'>    <div class="img bz2"></div>    <div class="name">        <div class="file fs-1-2 bold">betterbird-128.6.0esr-bb20.de.linux-x86_64.tar.bz2</div>     <div <class="data upper size fs-0-7"><span class="bold">Size:</ span> 80.26<span class="fs-0-8 bold">MB</span></div>        <div class="data upper modified fs-0-7"><span class="bold">Last modified:</ span> Tue. January 7th, 2025 - 10:54pm</div> </div></a></div><div class="block"><a href="LinuxArchive/betterbird-128.6.0esr-bb20.en- US.linux-x86_64.tar.bz2" class="bz2" download='betterbird-128.6.0esr- bb20.en-US.linux-x86_64.tar.bz2'> <div class="img bz2"></div>    <div class="name">        <div class="file fs-1-2 bold">betterbird-128.6.0esr-bb20.en-US.linux-x86_64.tar.bz2</div> <div class="data upper size fs-0-7"><span class="bold">Size:</span> 80.04<span class="fs-0-8 bold">MB</span></div>        <div class="data upper modified fs-0-7"><span class="bold">Last modified:</span> Tue. January 7th, 2025 - 10:42pm</div>    </div>    </a></div><div class="block"><a href="LinuxArchive/betterbird-128.6.0esr-bb20.es- AR.linux-x86_64.tar.bz2" class="bz2" download='betterbird-128.6.0esr- bb20.es-AR.linux-x86_64.tar.bz2'> <div class="img bz2"></div>    <div class="name">        <div class="file fs-1-2 bold">betterbird-128.6.0esr-bb20.es-AR.linux-x86_64.tar.bz2</div>


[1] > my @y = $x ~~ m:g/ <?before ^ | download > .*? <?before \> | \h+ > /;

[「download='betterbird-128.6.0esr-bb20.de.linux-x86_64.tar.bz2'」 「download='betterbird-128.6.0esr-bb20.en-US.linux-x86_64.tar.bz2'」 「download='betterbird-128.6.0esr-bb20.es-AR.linux-x86_64.tar.bz2'」]


[2] > for @y -> $Line  { print $Line ~ "\n"; }

download='betterbird-128.6.0esr-bb20.de.linux-x86_64.tar.bz2'
download='betterbird-128.6.0esr-bb20.en-US.linux-x86_64.tar.bz2'
download='betterbird-128.6.0esr-bb20.es-AR.linux-x86_64.tar.bz2'




Thank you!  Now to create a keeper out of it!

Reply via email to