RosettaCodeData/Task/Tokenize-a-string-with-escaping/Raku/tokenize-a-string-with-escaping.raku
2023-07-01 13:44:08 -04:00

6 lines
267 B
Raku

sub tokenize ($string, :$sep!, :$esc!) {
return $string.match(/([ <!before $sep | $esc> . | $esc . ]*)+ % $sep/)\
.[0].map(*.subst: /$esc )> ./, '', :g);
}
say "'$_'" for tokenize 'one^|uno||three^^^^|four^^^|^cuatro|', sep => '|', esc => '^';