How can i replace character with regex, but from variable. Example:
var separator = '-';
text = text.replace(/[-\s]+/g, separator);
this will replace - trailing character with separator, which i the same in this case.
So, i need to set this - character from variable separator:
var separator = '-';
var regex = '/['+separator+'\s]+/g';
text = text.replace(regex, separator);
How can i do this? Thanks.