简体   繁体   English

JavaScript正则表达式 - 空格,逗号和斜线

[英]JavaScript Regex - Whitespace, comma and slash

Would like to replace all instances of whitespace, commas and slashes in a string with a hyphen. 想用连字符替换字符串中的空格,逗号和斜杠的所有实例。

At the moment I am using 目前我正在使用

myString..replace(/\s+/g, "-").replace(/\//g, "-").replace(/,/,"-");

which is not nice I know but I tried something along the lines of 我知道这不好,但我尝试了一些方法

myString.replace(/s+,\//g, "-");

but to no avail. 但无济于事。

How should I organise the regex? 我应该如何组织正则表达式?

将所有内容放在除了\\s+之外的char类中。

myString.replace(/\s+|[,\/]/g, "-");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM