Suppose this string:
The fox jumped over the log.
Turning into:
To remove white space, considering leading, trailing and extra white space in between words, use:
(?<=\s) +|^ +(?=\s)| (?= +[\n\0])
The first or
deals with leading white space, the second or
deals with start of string leading white space, and the last one deals with trailing white space.
For proof of use, this link will provide you with a test.
https://regex101.com/r/meBYli/4
This is to be used with the re.split function.