Re: Regex surprises

2022-09-15 Thread Daniel Sockwell
Sean, To follow up on what Brian said, you can also do the same thing on a single line with named captures https://docs.raku.org/language/regexes#Named_captures (This often isn't as good as Brian's method, since breaking things up as Brian showed often helps readability. But it can be a good o

Regex surprises

2022-09-14 Thread Clifton Wood
Hi Brian, I would think this would become pretty easy. Consider: sub MAIN ( $replacement, :$x, :$y ) { my regex x {<{ $x }> } my regex y { <{$y}> } S:g! ! <{ $replacemement }> ! if $x; S:g! ! <{ $replacement }> ! if $y } Is this what you are looking for or did I miss something?

Re: Regex surprises

2022-09-13 Thread Brian Duggan
> > > ... > > > "y" ~~ /(x)|(y)/ I would probably take advantage of the composability of Raku regexes, and do something like my regex x { x } my regex y { y } and then use / | / and check for $ or $ > > S:g[(x)|(y)] = $0 ?? x-replacement !! y-replacement e.g. this becomes S:g[|] = $

Re: Regex surprises

2022-09-12 Thread Brad Gilbert
Raku removed all of the regex cruft that has accumulated over the years. (Much of that cruft was added by Perl.) I'm not going to respond to the first part of your email, as I think it is an implementation artifact. On Mon, Sep 12, 2022 at 3:06 PM Sean McAfee wrote: > Hello-- > > I stumbled acr

Regex surprises

2022-09-12 Thread Sean McAfee
Hello-- I stumbled across a couple of bits of surprising regex behavior today. First, consider: S:g[ x { say 1 } ] = say 2 given "xx" I expected this to print 1, 2, 1, 2, but it prints 1, 1, 2, 2. So it looks like, in a global substitution like this, Raku doesn't look for successive matches an