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

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:18 UTC
Read the original article Hit count: 252

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...

© Stack Overflow or respective owner

Related posts about regex

Related posts about python