I want to split a string by ,
->
, =>
, or those wrapped with several spaces, meaning that I can get two items, she
and <
If you can just strip your input string. From your description, all you need is to split the words on either \s+
or \s*->\s*
or \s*=>\s*
So here is my solution:
p = re.compile(r'\s*[-=]>\s*|\s+')
input1 = "she he"
input2 = " she -> he \n".strip()
print p.split(input1)
print p.split(input2)
Your output would be just 'she' and 'he':
['she', 'he']