How to split but ignore separators in quoted strings, in python?

Posted by Sly on Stack Overflow See other posts from Stack Overflow or by Sly
Published on 2010-05-07T02:13:05Z Indexed on 2010/05/07 2:28 UTC
Read the original article Hit count: 304

Filed under:
|

I need to split a string like this, on semicolons. But I don't what to split on semicolons that are inside of a string (' or "). I'm not parsing a file; just a simple string with no line breaks.

part 1;"this is ; part 2;";'this is ; part 3';part 4

Result should be:

  • part 1
  • "this is ; part 2"
  • 'this is ; part 4'
  • part 4

I suppose this can be done with a regex but if not; I'm open to another approach.

© Stack Overflow or respective owner

Related posts about regex

Related posts about python