I am trying to split a string using multiple delimiters. I need to keep the delimiters as words. The delimiters I am using are: all the punctuations marks and the space.
For example, the string:
Je suis, FOU et toi ?!
Should produce:
'Je'
'suis'
','
'FOU'
'et'
'toi'
'?'
'!'
I wrote:
class Parser :
def __init__(self) :
"""Empty constructor"""
def read(self, file_name) :
from string import punctuation
with open(file_name, 'r') as file :
for line in file :
for word in line.split() :
r = re.compile(r'[\s{}]+'.format(re.escape(punctuation)))
print(r.split(word))
But the result I got is:
['Je']
['suis', '']
['FOU']
['et']
['toi']
['', '']
The split seems to be correct, but the result list do not contains the delimiters :(