python - How to use regex to remove all symbols but replace blank with '-' -


i know regex, example

re.sub(r'[^\w]', '', string) 

i can remove symbols string. want remove other symbols replace blank '-'. there way that?

for example,

string = "felix's 3d's" # want "felixs-3d" 

thanks!

if want replace spaces - ignore , str.replace:

print(re.sub(r'[^\w\s]', '',string).replace(" ","-")) felixs-3ds 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -