JavaScript Regex-空格、逗号和斜线

JavaScript Regex - Whitespace, comma and slash

本文关键字:Regex- 空格 JavaScript      更新时间:2023-09-26

希望用连字符替换字符串中所有空格、逗号和斜杠的实例。

目前我正在使用

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

我知道这不太好,但我尝试了一些类似的东西

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

但无济于事。

我应该如何组织正则表达式?

将除's+之外的所有内容放入一个char类中。

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