Remove special characters from a string except whitespace

前端 未结 2 1475
既然无缘
既然无缘 2021-01-14 07:05

I am looking for a regular expression to remove all special characters from a string, except whitespace. And maybe replace all multi- whitespaces with a single whitespace.

2条回答
  •  旧时难觅i
    2021-01-14 07:48

    [ ](?=[ ])|[^-_,A-Za-z0-9 ]+
    

    Try this.See demo.Replace by empty string.See demo.

    http://regex101.com/r/lZ5mN8/69

提交回复
热议问题