Python Forum
spliting quoted and/or escaped tokens in a string
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
spliting quoted and/or escaped tokens in a string
#1
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.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
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.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020