Split multi-line string with shlex and keep quote characters

Viewed 7421

How do I split a string with Python's shlex while preserving the quote characters that shlex splits on?

Sample Input:

Two Words
"A Multi-line
 comment."

Desired Output:

['Two', 'Words', '"A Multi-line\ncomment."']

Note the double quotes wrapping the multi-line string. I read through the shlex documentation, but I don't see an obvious option. Does this require a regular expression solution?

2 Answers
Related