def parse_args(string):
    'Takes a string of whitespace-separated tokens and parses it into a list.\n    Whitespace inside tokens may be quoted with single quotes, double quotes or\n    backslash (similar to command-line arguments in bash).\n\n    >>> parse_args(r\'\'\'"a a" \'b b\' c\\ c "d\'d" \'e"e\' \'f\'f\' "g"g" "i""i" \'j\'\'j\' k" "k l\' l\' mm n\\n\'\'\')\n    [\'a a\', \'b b\', \'c c\', "d\'d", \'e"e\', "f\'f", \'g"g\', \'ii\', \'jj\', \'k k\', \'l l\', \'mm\', r\'n\n\']\n    '
    re_split = re.compile('((?:\n        [^\\s"\'\\\\] |\n        "(?: [^"\\\\] | \\\\.)*" |\n        \'(?: [^\'\\\\] | \\\\.)*\' |\n        \\\\.\n    )+)', re.VERBOSE)
    args = re_split.split(string)[1::2]
    args = [re.compile('"((?:[^"\\\\]|\\\\.)*)"').sub('\\1', x) for x in args]
    args = [re.compile("'((?:[^'\\\\]|\\\\.)*)'").sub('\\1', x) for x in args]
    return [re.compile('\\\\(.)').sub('\\1', x) for x in args]
Takes a string of whitespace-separated tokens and parses it into a list.
    Whitespace inside tokens may be quoted with single quotes, double quotes or
    backslash (similar to command-line arguments in bash).

    >>> parse_args(r'''"a a" 'b b' c\ c "d'd" 'e"e' 'f'f' "g"g" "i""i" 'j''j' k" "k l' l' mm n\n''')
    ['a a', 'b b', 'c c', "d'd", 'e"e', "f'f", 'g"g', 'ii', 'jj', 'k k', 'l l', 'mm', r'n
']
def parse_args(string):
    'Takes a string of whitespace-separated tokens and parses it into a list.\n    Whitespace inside tokens may be quoted with single quotes, double quotes or\n    backslash (similar to command-line arguments in bash).\n\n    >>> parse_args(r\'\'\'"a a" \'b b\' c\\ c "d\'d" \'e"e\' \'f\'f\' "g"g" "ii" \'j\'\'j\' k" "k l\' l\' mm n\\n\'\'\')\n    [\'a a\', \'b b\', \'c c\', "d\'d", \'e"e\', "f\'f", \'g"g\', \'ii\', \'jj\', \'k k\', \'l l\', \'mm\', r\'n\n\']\n    '
    re_split = re.compile('((?:\n        [^\\s"\'\\\\] |\n        "(?: [^"\\\\] | \\\\.)*" |\n        \'(?: [^\'\\\\] | \\\\.)*\' |\n        \\\\.\n    )+)', re.VERBOSE)
    args = re_split.split(string)[1::2]
    args = [re.compile('"((?:[^"\\\\]|\\\\.)*)"').sub('\\1', x) for x in args]
    args = [re.compile("'((?:[^'\\\\]|\\\\.)*)'").sub('\\1', x) for x in args]
    return [re.compile('\\\\(.)').sub('\\1', x) for x in args]