Splitting on spaces, except between certain characters

后端 未结 4 1579
既然无缘
既然无缘 2020-12-06 13:37

I am parsing a file that has lines such as

type(\"book\") title(\"golden apples\") pages(10-35 70 200-234) comments(\"good read\")

And I want to split

4条回答
  •  天命终不由人
    2020-12-06 14:25

    I would try using a positive look-behind assertion.

    r'(?<=\))\s+'
    

    Example:

    >>> import re
    >>> result = re.split(r'(?<=\))\s+', 'type("book") title("golden apples") pages(10-35 70 200-234) comments("good read")')
    >>> result
    ['type("book")', 'title("golden apples")', 'pages(10-35 70 200-234)', 'comments(
    "good read")']
    

提交回复
热议问题