简体   繁体   中英

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, "-");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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