How to split a string by commas positioned outside of parenthesis?

前端 未结 10 2112
南方客
南方客 2020-11-27 19:36

I got a string of such format:

\"Wilbur Smith (Billy, son of John), Eddie Murphy (John), Elvis Presley, Jane Doe (Jane Doe)\"

so basicly i

10条回答
  •  孤街浪徒
    2020-11-27 19:58

    split by ")"

    >>> s="Wilbur Smith (Billy, son of John), Eddie Murphy (John), Elvis Presley, Jane Doe (Jane Doe)"
    >>> s.split(")")
    ['Wilbur Smith (Billy, son of John', ', Eddie Murphy (John', ', Elvis Presley, Jane Doe (Jane Doe', '']
    >>> for i in s.split(")"):
    ...   print i.split("(")
    ...
    ['Wilbur Smith ', 'Billy, son of John']
    [', Eddie Murphy ', 'John']
    [', Elvis Presley, Jane Doe ', 'Jane Doe']
    ['']
    

    you can do further checking to get those names that doesn't come with ().

提交回复
热议问题