Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Split string, preserve quoted substring

I have a string that I’m trying to split such that the quoted substring stays preserved. Based on another thread here, I tried using shlex:

import shlex
shlex.split('“COBRA COMMANDER” Section 4Q/C')

However, the result isn’t what I expected:

['“COBRA', 'COMMANDER”', 'Section', '4Q/C']

I need the quoted text in one batch, something like:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

['“COBRA COMMANDER”', 'Section', '4Q/C']

what am I doing wrong?

>Solution :

You’re encountering a classic prank by your operating system, editor, or the original source of the data, "smart quotes", which are not ", but something else

>>> ord('"')
34
>>> ord('“')
8220
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading