Replace all non Alpha Numeric characters, New Lines, and multiple White Space with one Space

后端 未结 8 1543
终归单人心
终归单人心 2021-01-29 20:24

I\'m looking for a neat RegEx solution to replace

  • All non Alpha-Numeric Characters
  • All NewLines
  • All multiple instances of white space
8条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-29 20:56

    Well I think you just need to add a quantifier to each pattern. Also the carriage-return thing is a little funny:

    text.replace(/[^a-z0-9]+|\s+/gmi, " ");
    

    edit The \s thing matches \r and \n too.

提交回复
热议问题