Re: I need help understanding a match
On 1/16/25 1:41 AM, Todd Chester via perl6-users wrote: First I should apologize for one of my earlier posts. The first token was a bit of a jumble. I think now you just want the literal string "download" to start your capture. Hi Bill, Don't apologize. You are teaching me at trans light speed (FLT or Faster Than Light, it is coming to humanity soon). I sincerely appreciate it. I am still slowly reading over your post, bit by bit, to make sure I completely understand it. :-) -T
Re: I need help understanding a match
Thank you! On 1/13/25 18:20, William Michels via perl6-users wrote: Hi Todd, First I should apologize for one of my earlier posts. The first token was a bit of a jumble. I think now you just want the literal string "download" to start your capture. As per usual I tried a few different approaches to your regex problem, and posted what I thought was the best one, However an older iteration crept into one of my email posts: it used `^` which is Raku's zero-width "start-of-string" regex token. If you use `^` you will capture from the start-of-string onward, in this case through the `.*?` any-character token and up to the \> angle. You may not want this as it actually means the word "download" isn't required for you to capture that sequence of characters. I'm not sure where you got the impression that `\...\` actually means anything specific in Raku. If you're asking for a match against alphanumeric characters in Raku you don't have to escape them. Anything else (e.g. punctuation) you'll have to escape. So this means if you're trying to match ">" the "greater-than" sign (angle), you'll have to escape it via a backslash (e.g. `\>`), or by quoting (e.g. ">"). For non-alphanumeric characters, an unescaped punctuation characters is reserved for special "metacharacter" purposes: for example an unescaped "." dot means "any-character". You'll also note backslashing used to denote characters that are difficult to represent otherwise. Think for example how `\n` means newline, `\t` means tab. There are others: `\s` means whitespace, `\h` means horizontal-whitespace, and `\v` means vertical whitespace. Also `\S` means non-whitespace, `\H` means non- horizontal-whitespace, and `\V` means non- vertical-whitespace. I've also posted direct links to Raku regex forms, such as `` (a positive lookahead) and `` (a positive lookbehind). You can try this in the REPL: [0] > my $a = "XYZ" XYZ [1] > say $a ~~ m/ Y /; 「Y」 Try reading that out loud in English, "say $a smartmatching against a requested `m` match comprising after-X, Y, before-Z". If you read it that way, you'll understand why only the `「Y」` ends up in the match variable. You can also `andthen` the smartmatch, which will put the match in the `$_` topic variable for you, which can help with stringification: [1] > $a ~~ m/ Y / andthen put $_.Str; Y I'll try to go through and correct what you wrote below. Best, Bill. On Jan 12, 2025, at 03:11, ToddAndMargo via perl6-users wrote: Hi Bill, Please correct my notes. Many thanks, -T Explanation: my @y = $x ~~ m:g/ .*? | \h+ > /; `m:g` # match and global CORRECT `\...\` # the constrains (beginning and end) of the match NO, backslashes are used to escape non-alphanumeric characters, denote invisible characters (e.g. `\n`), etc. `<...>` # constraints of instructions inside the match NO, `` is a lookbehind and `` is a lookahead. First instruction: `` NO, this should just be the literal string `download` (or `"download"`) `?download ^` # positive look-behind, match but don`t capture `download ` # `^` means "look behind" `|` # This is logical "OR" `download ` # positive look-behind, match but don`t capture `download ` summary: capture everything behind `before ` or capture just `download` Second instruction: `.*?` `.*?` # any-character, one-or-more, frugal up to the third instruction YES, CORRECT Third instruction: ` | \h+ >` NO, SIMPLIFY THIS TO `` and the match will stop when it encounters ">" the "greater-than" sign (angle). Because you're using a lookahead (match characters and "lookahead" to find a pattern but don't capture, example ), the ">" angle doesn't get captured. `` # positive look-ahead, match but don`t capture `download \>` KINDA, the actual construct is ` >` or (even more readable), `" >` # Note that the `\` in `\>` is escaping the `>` and is removing KINDA, the `\` backslash in front of a non-alphanumeric is a rule in Raku. If it isn't backslashed Raku will try to interpret the non-alphanumeric as a metacharacter. # the `>` from the instructions constraints and making is part # of the match The unescaped `>` is part of the lookahead/lookbehind construct, either `` (lookbehind) or `` (lookahead). `|` # This is logical "OR" YES `\h+ ` # one-or-more horizontal whitespace character YES summary: capture everything before `before` or one-or-more whitespace characters KINDA. Match the previous tokens, and stop matching when (before) you find one-or-more whitespace characters. HTH.
Re: I need help understanding a match
Hi Todd, First I should apologize for one of my earlier posts. The first token was a bit of a jumble. I think now you just want the literal string "download" to start your capture. As per usual I tried a few different approaches to your regex problem, and posted what I thought was the best one, However an older iteration crept into one of my email posts: it used `^` which is Raku's zero-width "start-of-string" regex token. If you use `^` you will capture from the start-of-string onward, in this case through the `.*?` any-character token and up to the \> angle. You may not want this as it actually means the word "download" isn't required for you to capture that sequence of characters. I'm not sure where you got the impression that `\...\` actually means anything specific in Raku. If you're asking for a match against alphanumeric characters in Raku you don't have to escape them. Anything else (e.g. punctuation) you'll have to escape. So this means if you're trying to match ">" the "greater-than" sign (angle), you'll have to escape it via a backslash (e.g. `\>`), or by quoting (e.g. ">"). For non-alphanumeric characters, an unescaped punctuation characters is reserved for special "metacharacter" purposes: for example an unescaped "." dot means "any-character". You'll also note backslashing used to denote characters that are difficult to represent otherwise. Think for example how `\n` means newline, `\t` means tab. There are others: `\s` means whitespace, `\h` means horizontal-whitespace, and `\v` means vertical whitespace. Also `\S` means non-whitespace, `\H` means non- horizontal-whitespace, and `\V` means non- vertical-whitespace. I've also posted direct links to Raku regex forms, such as `` (a positive lookahead) and `` (a positive lookbehind). You can try this in the REPL: [0] > my $a = "XYZ" XYZ [1] > say $a ~~ m/ Y /; 「Y」 Try reading that out loud in English, "say $a smartmatching against a requested `m` match comprising after-X, Y, before-Z". If you read it that way, you'll understand why only the `「Y」` ends up in the match variable. You can also `andthen` the smartmatch, which will put the match in the `$_` topic variable for you, which can help with stringification: [1] > $a ~~ m/ Y / andthen put $_.Str; Y I'll try to go through and correct what you wrote below. Best, Bill. > On Jan 12, 2025, at 03:11, ToddAndMargo via perl6-users > wrote: > > Hi Bill, > > Please correct my notes. > > Many thanks, > -T > > > > Explanation: > my @y = $x ~~ m:g/ .*? | \h+ > /; > > `m:g` # match and global CORRECT > `\...\` # the constrains (beginning and end) of the match NO, backslashes are used to escape non-alphanumeric characters, denote invisible characters (e.g. `\n`), etc. > `<...>` # constraints of instructions inside the match NO, `` is a lookbehind and `` is a lookahead. > > > > First instruction: `` NO, this should just be the literal string `download` (or `"download"`) > > `?download ^` # positive look-behind, match but don`t capture `download ` > # `^` means "look behind" > > `|` # This is logical "OR" > > `download ` # positive look-behind, match but don`t capture `download ` > > summary: capture everything behind `before ` or capture just `download` > > > Second instruction: `.*?` > `.*?` # any-character, one-or-more, frugal up to the third instruction YES, CORRECT > > > Third instruction: ` | \h+ >` NO, SIMPLIFY THIS TO `` and the match will stop when it encounters ">" the "greater-than" sign (angle). Because you're using a lookahead (match characters and "lookahead" to find a pattern but don't capture, example ), the ">" angle doesn't get captured. > > `` # positive look-ahead, match but don`t capture `download \>` KINDA, the actual construct is ` >` or (even more readable), `" >` > # Note that the `\` in `\>` is escaping the `>` and is > removing KINDA, the `\` backslash in front of a non-alphanumeric is a rule in Raku. If it isn't backslashed Raku will try to interpret the non-alphanumeric as a metacharacter. > # the `>` from the instructions constraints and making is > part > # of the match The unescaped `>` is part of the lookahead/lookbehind construct, either `` (lookbehind) or `` (lookahead). > > `|` # This is logical "OR" YES > > `\h+ ` # one-or-more horizontal whitespace character YES > > summary: capture everything before `before` or one-or-more whitespace > characters KINDA. Match the previous tokens, and stop matching when (before) you find one-or-more whitespace characters. > > HTH.
Re: I need help understanding a match
On 1/12/25 3:11 AM, ToddAndMargo via perl6-users wrote: `?download ^` # positive look-behind, match but don`t capture `download ` # `^` means "look behind" Opps, that should be: `?before ^` # positive look-behind, match but don`t capture `download ` # `^` means "look behind"
Re: I need help understanding a match
Hi Bill, Please correct my notes. Many thanks, -T Explanation: my @y = $x ~~ m:g/ .*? | \h+ > /; `m:g` # match and global `\...\` # the constrains (beginning and end) of the match `<...>` # constraints of instructions inside the match First instruction: `` `?download ^` # positive look-behind, match but don`t capture `download ` # `^` means "look behind" `|` # This is logical "OR" `download ` # positive look-behind, match but don`t capture `download ` summary: capture everything behind `before ` or capture just `download` Second instruction: `.*?` `.*?` # any-character, one-or-more, frugal up to the third instruction Third instruction: ` | \h+ >` `` # positive look-ahead, match but don`t capture `download \>` # Note that the `\` in `\>` is escaping the `>` and is removing # the `>` from the instructions constraints and making is part # of the match `|` # This is logical "OR" `\h+ ` # one-or-more horizontal whitespace character summary: capture everything before `before` or one-or-more whitespace characters
Re: I need help understanding a match
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 > #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, ` | \h+ >` could be simplified to either ` >` or ``. 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, ``. 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/ #positive look-behind, match but dont capture download\= .*? #any-character, one-or-more, frugal > #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 [email protected]> 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/ .*? \> | \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'> class="name"> betterbird-128.6.0esr-bb20.de.linux-x86_64.tar.bz2 class="data upper size fs-0-7">Size: 80.26MB Last modified: Tue. January 7th, 2025 - 10:54pm class="block"> class="name"> betterbird-128.6.0esr-bb20.en-US.linux-x86_64.tar.bz2 class="data upper size fs-0-7">Size: 80.04MB Last modified: Tue. January 7th, 2025 - 10:42pm class="block"> class="name"> betterbird-128.6.0esr-bb20.es-AR.linux-x86_64.tar.bz2} download='betterbird-128.6.0esr-bb20.de.linux-x86_64.tar.bz2'> class="img bz2"> betterbird-128.6.0esr-bb20.de.linux-x86_64.tar.bz2 Size:span> 80.26MB class="data upper modified fs-0-7">Last modified:span> Tue. January 7th, 2025 - 10:54pm class="block"> class="name"> betterbird-128.6.0esr-bb20.en-US.linux-x86_64.tar.bz2 class="data upper size fs-0-7">Size: 80.04MB Last modified: Tue. January 7th, 2025 - 10:42pm class="block"> class="name"> betterbird-128.6.0esr-bb20.es-AR.linux-x86_64.tar.bz2 [1] > my @y = $x ~~ m:g/ .*? | \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!
Re: I need help understanding a match
~$
/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
> #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, ` | \h+ >` could be simplified to
either ` >` or ``. 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, ``. 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/
#positive look-behind, match but dont capture
download\=
.*?#any-character, one-or-more, frugal
> #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
> 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/ .*? |
> \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'>
> betterbird-128.6.0esr-bb20.de.linux-x86_64.tar.bz2 class="data upper size fs-0-7">Size: 80.26 class="fs-0-8 bold">MBLast modified: Tue. January 7th, 2025 -
> 10:54pm 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'>
> betterbird-128.6.0esr-bb20.en-US.linux-x86_64.tar.bz2 class="data upper size fs-0-7">Size: 80.04 class="fs-0-8 bold">MBLast modified: Tue. January 7th, 2025 -
> 10:42pm 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'>
> betterbird-128.6.0esr-bb20.es-AR.linux-x86_64.tar.bz2}
> download='betterbird-128.6.0esr-bb20.de.linux-x86_64.tar.bz2'> class="img bz2">betterbird-128.6.0esr-bb20.de.linux-x86_64.tar.bz2 Size: 80.26 class="fs-0-8 bold">MBLast modified: Tue. January 7th, 2025 -
> 10:54pm 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'>
> betterbird-128.6.0esr-bb20.en-US.linux-x86_64.tar.bz2 class="data upper size fs-0-7">Size: 80.04 class="fs-0-8 bold">MBLast modified: Tue. January 7th, 2025 -
> 10:42pm 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'>
> betterbird-128.6.0esr-bb20.es-AR.linux-x86_64.tar.bz2
>
>
> [1] > my @y = $x ~~ m:g/ .*? | \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'
>
