Regex remove all special characters except numbers?

前端 未结 5 1917
滥情空心
滥情空心 2021-01-31 09:09

I would like to remove all special characters (except for numbers) from a string. I have been able to get this far

var name = name.replace(/[^a-zA-Z ]/, \"\");
<         


        
5条回答
  •  遥遥无期
    2021-01-31 09:22

    This should work as well

    text = 'the car? was big and* red!'

    newtext = re.sub( '[^a-z0-9]', ' ', text)

    print(newtext)

    the car was big and red

提交回复
热议问题