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
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.
You may use re.findall.
>>> string ="someText:someValue~"
>>> re.findall(r'^([^:~]*)([:~])([^:~].*)', string)
[('someText', ':', 'someValue~')]
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)
[':', '~', '#']