I define a split function as lambda x: re.split('[(|)|.]', x), and when I applied this function to my original strings, it always generates some empty strings. For example:
When applied to string:
(Type).(Terrorist organization)AND(Involved in attacks).(nine-eleven)
The result is:
['', 'Type', '', '', 'Terrorist organization', 'AND', 'Involved in attacks', '', '', 'nine-eleven', '']
I know I can simply remove those empty strings manually, but is there any smart way to get rid of them?
|multiple times in the[]character set?[..]means match any character inside. You can’t use capture groups inside them.[().]will match the literal characters present.(,|,),.) inside the square brackets is considered a separate delimiter.