Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Tux
Created November 5, 2015 20:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tux/41263465dcb3b12ded2f to your computer and use it in GitHub Desktop.
Save Tux/41263465dcb3b12ded2f to your computer and use it in GitHub Desktop.
use v6;
# string to parse
my Str $str = ',"I said, ""Hi!""",';
# three alternatives for eol, separator, and quote
# as escape is identical to quote, I do not need to repeat
my @re = "\r\n", "\r", "\n", ",", "\"";
my @chunks = $str.split(@re, :keep-indices, :skip-empty);
dd $str;
dd @re;
dd @chunks;
with skip-empty
Str $var = ",\"I said, \"\"Hi!\"\"\","
Array $var = $["\r\n", "\r", "\n", ",", "\""]
Array $var = $["I said", 3, " ", 4, "Hi!", 4]
without skip-empty
Str $var = ",\"I said, \"\"Hi!\"\"\","
Array $var = $["\r\n", "\r", "\n", ",", "\""]
Array $var = $["", 3, "", 4, "I said", 3, " ", 4, "", 4, "Hi!", 4, "", 4, "", 4, "", 3, ""]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment