01:30 Manifest0 left 02:45 librasteve_ left 10:11 Manifest0 joined 11:38 librasteve_ joined
Manifest0 How do i get the capture of an interpolated regular expression? 19:11
my $reg = "'o' (.*?) 'l'" ; "old" ~~ /<$reg>/
it matches but $0 is Nil 19:12
librasteve m: my regex reg {'o' (.*?) 'd'} ; "old" ~~ /<reg>/; say ~$/<reg>[0] 19:32
Raku eval l
librasteve coupla hints 19:33
use keyword regex and a {} block (no $ on the name) 19:34
I recommend dd $/ to look at your match object
then you can dereference the bit you want here $/<reg>[0] and stringify it with ~ 19:35
m: my regex reg {'o' (.*?) 'd'} ; "old" ~~ /<reg>/; say $<reg>[0] 19:36
Raku eval 「l」
librasteve my regex reg {'o' (.*?) 'd'} ; "old" ~~ /<reg>/; say ~$<reg>[0]
Manifest0 i have the regexes in a file, and then i'm reading them with $file.IO.lines 19:37
and i need to check if those regex match, that's why i have them in a var
librasteve okaaay - what happens if you put them in a regular $var and just put that in the block? like my regex {$var}; ? 19:40
Manifest0 for 'regexes'.IO.lines() -> $r {my $rgp = rx {<$r>}; "odd" ~~ $rgp; say $0} 19:41
Nil
if i do dd $/ i get: $/ = Match.new(:orig("odd"), :from(0), :pos(2)) 19:42
changing "my $rgp = rx {<$r>};" to "my $rgp = rx {$r};" doesn't work at all 19:45
librasteve lemme check the docs 19:47
docs.raku.org/syntax/Regex%20Interpolation
Manifest0 there's no example where captures are used :-( 19:51
librasteve sorry - im in the middle of cooking/eating dinner ... back in a while 20:01
20:09 MasterDuke joined 20:43 notna joined 20:45 notna left 20:46 notna joined, notna left
ok - fwiw I have tried eg found this stackoverflow.com/questions/651449...ted-regex, but - like you - I have drawn a blank 21:14
looks like will have to fall back to eval 21:15
sorry I was unable to help - another option would be to post your question on StackOverflow [raku] tag ... I know that raiph is still pretty active and he has a better handle on this than I do 21:32
I need to hit the sack - but will try to check in tomorrow (eg if you need any help on the eval approach) 21:33
&afk
Manifest0 librasteve_: thanks 21:42
with a named capture it works: for 'regexes'.IO.lines() -> $r {my $rgp = rx {<test=$r>}; "odd" ~~ $rgp; say $<test>[0]} 21:55
librasteve oh - dang - I tried this my $reg = q|'o' (.*?) 'd'|; "old" ~~ /(<$reg>)/; which failed ... but you seem to have cracked the code!!! 22:25
but since you have that going now, maybe for 'regexes'.IO.lines() -> $r {my $rgp = rx {(<$r>)}; "odd" ~~ $rgp; say $<r>[0]} this will work? curious... 22:29
Manifest0 no. it doesn't work
librasteve ok - guess the name is the way to lift it - kudos to you 22:30
Manifest0 for 'regexes'.IO.lines() -> $r {my $rgp = rx {(<$r>)}; "odd" ~~ $rgp; dd $/} => $/ = Match.new(:orig("odd"), :from(0), :pos(3), :list((Match.new(:orig("odd"), :from(0), :pos(3)),))) 22:31