Re: I need help understanding a match

[email protected] (ToddAndMargo via perl6-users) Sun, 12 Jan 2025 03:11:08 -0800
Newsgroups perl.perl6.users
Message-ID <[email protected]>
Hi Bill,

Please correct my notes.

Many thanks,
-T



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

`m:g`     # match and global
`\...\`   # the constrains (beginning and end) of the match
`<...>`   # constraints of instructions inside the match



First instruction: `<?before ^ | 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


Third instruction: `<?before \> | \h+ >`
    `<?before \>`  # 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