I need to write a function using regular expressions, func(string)
, which returns the resulting list as a result of splitting the string. The separators can be enclosed commas with optional spaces or single colons. Look on 'spaces' in example with :
and ,
. I don't know how to achieve this effect.
Result which I will expect:
>>> func("foo, bar , sss:s")
['foo', 'bar', 'sss', 's']
>>> func("foo"),
['foo']
>>> func("bla : bla"),
'bla ', ' bla'
I have this for now:
import re
def func(t):
match = re.split(r'[,:]', t)
return match