Here\'s the simplest way to explain this. Here\'s what I\'m using:
re.split(\'\\W\', \'foo/bar spam\\neggs\') -> [\'foo\', \'bar\', \'spam\', \'eggs\'] >
replace all seperator: (\W) with seperator + new_seperator: (\W;)
seperator: (\W)
seperator + new_seperator: (\W;)
split by the new_seperator: (;)
new_seperator: (;)
def split_and_keep(seperator, s): return re.split(';', re.sub(seperator, lambda match: match.group() + ';', s)) print('\W', 'foo/bar spam\neggs')