Python Forum
spliting quoted and/or escaped tokens in a string - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: General (https://python-forum.io/forum-1.html)
+--- Forum: News and Discussions (https://python-forum.io/forum-31.html)
+--- Thread: spliting quoted and/or escaped tokens in a string (/thread-20968.html)



spliting quoted and/or escaped tokens in a string - Skaperen - Sep-08-2019

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.


RE: spliting quoted and/or escaped tokens in a string - Skaperen - Sep-08-2019

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.