How to remove ↵ character from JS string

后端 未结 4 676
北海茫月
北海茫月 2020-12-15 12:42

I have a string like

↵my name is Pankaj↵

I want to remove the character from the string.

\"↵select * from e         


        
4条回答
  •  难免孤独
    2020-12-15 13:15

    With something like

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

    you can for example keep only alphabetic (a-zA-Z), numeric (0-9) underscores and spaces.

    Some characters require to be specified with a backslash in front of them (for example ], -, / and the backslash itself).

    You are however going to run into problems when your start deploying to an international audience, where "strange characters" are indeed the norm.

提交回复
热议问题