No matter how much I look for it, I only see cutting based on blank characters and removing blank characters from the front and back I can't cut strings based on multiple characters.
mystr = Hey, you - what are you doing here!?
-> ['hey', 'you', 'what', 'are', 'you', 'doing', 'here']
Blank + special character , like -?!I'd like to distribute all strings based on
.
But Python str.split() only gets one factor. What should I do?
string python split
import re
DATA = "Hey, you - what are you doing here!?"
print re.findall(r"[\w']+", DATA)
# # Prints ['Hey', 'you', 'what', 'are', 'you', 'doing', 'here']
import re
DATA = "Hey, you - what are you doing here!?"
print re.split('\W+', DATA) # ['Hey', 'you', 'what', 'are', 'you', 'doing', 'here', '']
'a;bcd,ef g'.replace(';',' ').replace(',',' ').split()
= ['a', 'bcd', 'ef', 'g']
You do not need to import modules The disadvantage is that replace() accepts only one factor and requires multiple calls.
© 2025 OneMinuteCode. All rights reserved.