re.split("\\W+", words)
I have the code above which splits the string at all punctuation but how do I split it at all punctuation except for the '-' symbol?
Use re.split(r'[^-\w]+', words)
Where ^
inside the character group indicates not to split on ( -
or any alphabet
) characters.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.