Split a string by spaces — preserving quoted substrings — in Python

后端 未结 16 694
心在旅途
心在旅途 2020-11-22 15:05

I have a string which is like this:

this is \"a test\"

I\'m trying to write something in Python to split it up by space while ignoring spac

16条回答
  •  太阳男子
    2020-11-22 15:29

    As an option try tssplit:

    In [1]: from tssplit import tssplit
    In [2]: tssplit('this is "a test"', quote='"', delimiter='')
    Out[2]: ['this', 'is', 'a test']
    

提交回复
热议问题