I want to remove all special characters and spaces from a string and replace with an underscore.
The string is
var str = "hello world & hello universe";
I have this now which replaces only spaces:
str.replace(/\s/g, "_");
The result I get is `hello_world_&_hello_universe`, but I would like to remove the special symbols as well.
I tried this `str.replace(/[^a-zA-Z0-9]\s/g, "_")` but this does not help.
以上就是Remove special symbols and extra spaces and replace with underscore using the replace method的详细内容,更多请关注web前端其它相关文章!