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

后端 未结 8 1536
终归单人心
终归单人心 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.

    0 讨论(0)
  • 2021-01-29 20:58

    A saw a different post that also had diacritical marks, which is great

    s.replace(/[^a-zA-Z0-9À-ž\s]/g, "")

    0 讨论(0)
提交回复
热议问题