This channel is intended for people just starting with the Raku Programming Language (raku.org). Logs are available at irclogs.raku.org/raku-beginner/live.html
Set by lizmat on 8 June 2022.
00:31 nicole joined 02:24 teatime left, teatime joined 02:35 teatwo joined 02:39 teatime left 03:54 MasterDuke left 07:48 dakkar joined
Tirifto Hello! Is there a way I can ask a regex to match the whole string, when the regex itself does not start and end with ^ and $, respectively? I thought of something like /^<$regex>$/, but is there perhaps a more ‘direct’ way? 12:52
lizmat "foo" ~~ / f / && $/.from == 0 would cover the start position 12:57
"foo" ~~ / f / && $/.from == 0 && $/.pos == "foo".chars 12:58
Tirifto Oh! 13:00
Thank you, lizmat! I didn’t realise those were available. :D Although the docs say that the output of .pos is unspecified; should I use .to instead? 13:03
lizmat yeah, probably should use .to :-) 13:04
m: sub infix:<~=~>($a, $b) { $a.match($b); $/.from == 0 && $/.to == $a.chars }; say "foo" ~=~ / foo / 13:11
camelia True
lizmat m: sub infix:<~=~>($a, $b) { $a.match($b); $/.from == 0 && $/.to == $a.chars }; say "foo" ~=~ / oo /
camelia False
lizmat another approach: 13:12
m: sub infix:<~=~>($a, $b) { $a.match($b); $/.from == 0 && $/.to == $a.chars ?? $/ !! Nil }; say "foo" ~=~ / foo /
camelia 「foo」
lizmat m: sub infix:<~=~>($a, $b) { $a.match($b); $/.from == 0 && $/.to == $a.chars ?? $/ !! Nil }; say "foo" ~=~ / oo /
camelia Nil
Tirifto Oh, that’s a nice idea! And it seems to fit in very well. 13:17
lizmat from a performance point of view, it may actually be better to use / ^ <$regex> $ / 13:19
with a small needle and a large haystack, the regex engine could potentially do a lot of work
whereas a ^ would allow it to stop immediately if the first character didn't match 13:20
so YMMV
Tirifto An excellent point, too. `o` 13:30
lizmat m: m: sub infix:<~=~>($a, $b) { $a.match(/ ^ <$b> $/) }; say "foo" ~=~ / oo / # maybe better
camelia Nil
lizmat m: m: sub infix:<~=~>($a, $b) { $a.match(/ ^ <$b> $/) }; say "foo" ~=~ / foo / # maybe better
camelia 「foo」
14:24 tea3po joined 14:27 teatwo left 15:19 Guest823 joined 15:21 Guest823 left 15:22 Guest152 joined 15:23 Guest152 left 15:25 Guest6440 joined 15:27 Guest6440 left 15:29 Guest3759 joined 15:34 Guest3759 left 16:45 dakkar left 20:53 p6steve_ left