Is this possible in Javascript?
I have this from Java, but can not be used in Javascript.
s/-{2,}/-/g
Is there another way that works?
See Question&Answers more detail:osIs this possible in Javascript?
I have this from Java, but can not be used in Javascript.
s/-{2,}/-/g
Is there another way that works?
See Question&Answers more detail:osYes it is. You can use the same regex with the Javascript replace()
method.
s.replace(find, replacement)
// where 's' is your string object
Example:
var r = 'foo--bar---baz'.replace(/-{2,}/g, '-');
console.log(r); // "foo-bar-baz"