In Python, how do I split a string and keep the separators? September 29, 2022 by Tarik >>> re.split('(\W)', 'foo/bar spam\neggs') ['foo', "https://stackoverflow.com/", 'bar', ' ', 'spam', '\n', 'eggs']