Python Forum

Full Version: spliting quoted and/or escaped tokens in a string
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
i think i asked this a while back because i remember a "can't find anything" answer. so i wonder if any answers have popped up. i want to do a generic split like the str.split() method with no arguments, but with support for tokens that are quoted within the string being split and might even have spaces, such as "foo 'foo bar' bar" -> ['foo','foo bar','bar'] as well as support for backslash escape sequences (doubled here like you would in python source code) "foo foo\\ bar bar" giving the same list. you might get strings like this reading from a file.
now i am thinking it could be useful if there was a way to have a string parsed as code and return the parse tree.