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

前端 未结 3 1474
臣服心动
臣服心动 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:11

    You can use re.findall to find the none words delimiters using look around:

    >>> string ="someText:someValue~andthsi#istest@"
    >>> re.findall('(?<=\w)(\W)(?=\w)',string)
    [':', '~', '#']
    

提交回复
热议问题