ChanneW
2014-11-14 12:43:25 +08:00
def tsplit(string, delimiters):
"""Behaves str.split but supports multiple delimiters."""
delimiters = tuple(delimiters)
stack = [string,]
for delimiter in delimiters:
for i, substring in enumerate(stack):
substack = substring.split(delimiter)
stack.pop(i)
for j, _substring in enumerate(substack):
stack.insert(i+j, _substring)
return stack
s ="<Data>1=1&2=2</Data><Data>abc</Data><Data>nihao</Data>"
tsplit(s, (',', '<Data>', '</Data>'))