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?
Put all inside a char class except \s+
.
myString.replace(/\s+|[,\/]/g, "-");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With