You get this warning because with the pattern \s* you asked to split into substrings of zero or more spaces
But ... an empty string matches this pattern, because it has zero spaces in it!
It is not clear what to do with this re.split . This is what str.split does:
>>> 'hello world'.split('') Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: empty separator >>>
re.split decides to simply throw away this empty substring option and instead break it into one or more spaces. In python3.6, it emits what FutureWarning you see to tell you about this solution.
You could say it yourself by replacing * with + :
$ python3.6 -c "import re; print(re.split('\s*', 'I am going to school'))" /usr/lib64/python3.6/re.py:212: FutureWarning: split() requires a non-empty pattern match. return _compile(pattern, flags).split(string, maxsplit) ['I', 'am', 'going', 'to', 'school'] $ python3.6 -c "import re; print(re.split('\s+', 'I am going to school'))" ['I', 'am', 'going', 'to', 'school']
source share