Q:

Regex does not remove the special chars in split function

I am using a regex to split a string into an array of substrings
Input: mark bill #special# #special method# johni
import re
re.split('[ #, #]+', 'mark bill #special# #special method# johni')

When I execute this command the result is: ['mark', 'bill', 'special', 'special method' 'johni']
That's right, but in string 'special' I don't want to remove the special chars #
I want this result:: ['mark', 'bill', '#special#', #special method#, 'johni']
Is it possible?
Thanks.

A:

Rather than split you should use findall:
print re.findall(r'#[^#]*#|\S+', 'mark bill #special# #special method# johni')

Output:
['mark', 'bill', '#special#', '#special method#', 'johni']

