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

前端 未结 3 1481
臣服心动
臣服心动 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 20:55

    string ="someText:someValue~"
    print re.split("(:|~)",string,1)
    

    If you put in group,it will appear in the list returned.You can find it from 1 index of list.

提交回复
热议问题