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

javascript - Js, document.getElementById("ID").innerHTML, error -

jquery - jqGrid update specific column data with out refreshing the entire column? -

objective c - Is there a way in OCMockito to make stubs fail when an unknown method is called? -