I just got introduced to the re
module and I learnt that it could be used to split strings very well. Then I wrote the following code:
import re
print(re.split(r'[a-f]','abcdefghtuyi op re the'))
I expected that Python would return:
['ghtuyi op r', ' th',] # as all the alphabets from a to f are expected to be sliced
But it returned:
['' '', '', '', '', '', 'ghtuyi op r', ' th', '']
Why are these blank list objects appearing?
Also, I did take a look at this question: Why are empty strings returned in split() results? but it has nothing to do with re
. How do I get rid of these blank objects while using the re
module?