Python split a string w/ multiple delimiter and find the delimiter used

前端 未结 3 1475
臣服心动
臣服心动 2021-01-13 20:40

How to split string with multiple delimiters and find out which delimiter was used to split the string with a maxsplit of 1.

import re

string =\"someText:so         


        
3条回答
  •  一整个雨季
    2021-01-13 21:04

    You may use re.findall.

    >>> string ="someText:someValue~"
    >>> re.findall(r'^([^:~]*)([:~])([^:~].*)', string)
    [('someText', ':', 'someValue~')]
    

提交回复
热议问题