Re: Working with a regex using positional captures stored in a variable

2021-03-22 Thread Ralph Mellor
On Mon, Mar 22, 2021 at 2:50 PM yary wrote: > > how to get all nested captures worked for me ... not sure I agree with the > design I think the current flattening aspect is awkward in a couple ways: * Having to specify ``. I half like Brad's suggestion. * Having to write `.pairs` to extract

Re: Working with a regex using positional captures stored in a variable

2021-03-22 Thread yary
Hi all, Thanks Bill for posting your results from my samples. Seems like we both get lots of warnings/errors from our REPL's, me even with 2021.02.01. I suspect there must be something going on with what the REPL is trying to print, after all it does want to display the results of every line. I

Re: Working with a regex using positional captures stored in a variable

2021-03-20 Thread William Michels via perl6-users
Hi Yary, I ran your Raku code in a script (on MacOS) and in the REPL (MacOS with Linenoise). All results below with Rakudo_2020.10: #Script: my $word = /(\w+)/; my $AwithB = /$word' with '$word/; $_= 'Interpolating regexes with arbitrary captures is fun!'; say "Nested rx"; dd m/$AwithB.*'is

Re: Working with a regex using positional captures stored in a variable

2021-03-20 Thread Ralph Mellor
On Wed, Mar 17, 2021 at 7:17 PM William Michels via perl6-users wrote: > > ("If the first character inside is anything other than an alpha it doesn't > capture"). > It should be added to the Raku Docs ASAP. Fyi, here's how Larry Wall expressed it 15-18 years ago: > A leading alphabetic

Re: Working with a regex using positional captures stored in a variable

2021-03-19 Thread Ralph Mellor
On Fri, Mar 19, 2021 at 6:12 PM yary wrote: > > I don't know how to get the result. > DB<1> $word = qr/(\w+)/; > DB<2> $AwithB = qr/$word with $word/ > DB<3> $_ = 'Interpolating regexes with arbitrary captures is fun!' > DB<4> x /$AwithB.*is $word/ A Raku equivalent: my $word = '(\w+)'; my

Re: Working with a regex using positional captures stored in a variable

2021-03-19 Thread yary
My current expectations are a little different than any others previously expressed and I don't know how to get the result. I am no longer considering named captures from Regex's interpolated inside and am now looking at directly interpolating them. Perl example: DB<1> *$word = qr/(\w+)/;*

Re: Working with a regex using positional captures stored in a variable

2021-03-18 Thread Ralph Mellor
On Thu, Mar 18, 2021 at 12:59 AM yary wrote: > > As it is I get same kinds of errors in the REPL, perhaps it is MacOS > with Linenoise that's mucking that up. I can confirm your new test code also works fine in both program and repl forms in 2020.12. Though obviously the case you mark as

Re: Working with a regex using positional captures stored in a variable

2021-03-17 Thread yary
Thanks raiph for everything! Including getting me to upgrade my Raku, "Welcome to Rakudo(tm) v2021.02.1. Implementing the Raku(tm) programming language v6.d. Built on MoarVM version 2021.02." As it is I get same kinds of errors in the REPL, perhaps it is MacOS with Linenoise that's mucking

Re: Working with a regex using positional captures stored in a variable

2021-03-17 Thread Ralph Mellor
> 1. The list you posted is fantastic ("If the first character inside is > anything other > than an alpha it doesn't capture"). It should be added to the Raku Docs ASAP. Not the list, right? Just the rule. (There are dozens of kinds of assertions. No one is going to remember the list.) If you

Re: Working with a regex using positional captures stored in a variable

2021-03-17 Thread Ralph Mellor
And when I cut/paste from the doc, the number example works too, in both script and repl. On Wed, Mar 17, 2021 at 10:33 PM Ralph Mellor wrote: > > Er, by wfm I mean it matches 「Is」 as the code suggests. > > On Wed, Mar 17, 2021 at 10:32 PM Ralph Mellor wrote: > > > > Works for me in Rakudo

Re: Working with a regex using positional captures stored in a variable

2021-03-17 Thread Ralph Mellor
Er, by wfm I mean it matches 「Is」 as the code suggests. On Wed, Mar 17, 2021 at 10:32 PM Ralph Mellor wrote: > > Works for me in Rakudo 2020.12. > > On Wed, Mar 17, 2021 at 9:33 PM yary wrote: > > > > The "Interpolation" section of the raku docs use strings as the elements of > > building up a

Re: Working with a regex using positional captures stored in a variable

2021-03-17 Thread Ralph Mellor
Works for me in Rakudo 2020.12. On Wed, Mar 17, 2021 at 9:33 PM yary wrote: > > The "Interpolation" section of the raku docs use strings as the elements of > building up a larger regex from smaller pieces, but the example that looks > fruitful isn't working in my raku. This is taken from >

Re: Working with a regex using positional captures stored in a variable

2021-03-17 Thread yary
The "Interpolation" section of the raku docs use strings as the elements of building up a larger regex from smaller pieces, but the example that looks fruitful isn't working in my raku. This is taken from https://docs.raku.org/language/regexes#Regex_interpolation > my $string = 'Is this a regex

Re: Working with a regex using positional captures stored in a variable

2021-03-17 Thread William Michels via perl6-users
Dear Brad, 1. The list you posted is fantastic ("If the first character inside is anything other than an alpha it doesn't capture"). It should be added to the Raku Docs ASAP. 2. There are some shortcuts that don't seem to follow a set pattern. For example a named capture can be accessed using $

Re: Working with a regex using positional captures stored in a variable

2021-03-17 Thread Joseph Brenner
And once again, thanks much for the explication of all this... But even after thinking it over, the current state-of-affairs on this really doesn't strike me as being okay. As I'm sure everyone here knows, over in perl-land the main trick you have for creating regexes from components is lexical

Re: Working with a regex using positional captures stored in a variable

2021-03-13 Thread Brad Gilbert
It makes <…> more consistent precisely because <$pattern> doesn't capture. If the first character inside is anything other than an alpha it doesn't capture. Which is a very simple description of when it captures. doesn't capture because of the 「?」 doesn't capture because of the 「!」

Re: Working with a regex using positional captures stored in a variable

2021-03-13 Thread Joseph Brenner
Thanks much for your answer on this. I think this is the sort of trick I was looking for: Brad Gilbert wrote: > You can put it back in as a named > > $input ~~ / > 「9 million」 > pattern => 「9 million」 > 0 => 「9」 > 1 => 「million」 That's good enough, I guess, though

Re: Working with a regex using positional captures stored in a variable

2021-03-11 Thread Brad Gilbert
If you interpolate a regex, it is a sub regex. If you have something like a sigil, then the match data structure gets thrown away. You can put it back in as a named > $input ~~ / 「9 million」 pattern => 「9 million」 0 => 「9」 1 => 「million」 Or as a numbered: >

Working with a regex using positional captures stored in a variable

2021-03-11 Thread Joseph Brenner
Does this behavior make sense to anyone? When you've got a regex with captures in it, the captures don't work if the regex is stashed in a variable and then interpolated into a regex. Do capture groups need to be defined at the top level where the regex is used? { # From a code example in the