Q:

How to split sentence to words with regular expression?

"She's so nice!" -> ["she","'","s","so","nice","!"]
I want to split sentence like this!
so I wrote the code, but It includes white space!
How to make code only using regular expression?
        words = re.findall('\W+|\w+')

-> ["she", "'","s", " ", "so", " ", "nice", "!"]
        words = [word for word in words if not word.isspace()]

A:

Regex: [A-Za-z]+|[^A-Za-z ]
In [^A-Za-z ] add chars you don't want to match.
Details:

[] Match a single character present in the list
[^] Match a single character NOT present in the list
+ Matches between one and unlimited times
| Or

Python code:
text = "She's so nice!"
matches = re.findall(r'[A-Za-z]+|[^A-Za-z ]', text)

Output:
['She', "'", 's', 'so', 'nice', '!']

Code demo

