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?
Yes it is. You can use the same regex with the Javascript replace() method.
replace()
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"
1.4m articles
1.4m replys
5 comments
57.0k users