Regex to replace "--" with "-"

function spinalCase(str) {
  var reg = new RegExp('\\s','g');
  var regun = new RegExp('\x5F','g');
  var regdd = new RegExp("#" + "--" + "#", "g");
  str = str.replace(regun,'-');
  str = str.replace(reg,"-");
  str = str.split('');
  var ind = [];
  for(i=0;i<str.length;i++){
    if(str[i] == str[i].toUpperCase() && str[i]!='-'){
        str[i] = str[i].toLowerCase();
        ind.push(i);
    }
  }
  for(i=0;i<ind.length;i++){
    if (ind[i]!=0){
      str[ind[i]] = "-" + str[ind[i]];
    }
  }
  str = str.join('');
  str = str.replace(regdd,'-');
  return str;
}

I’m trying to replace the “–” with “-”, I found this: https://stackoverflow.com/questions/17885855/use-dynamic-variable-string-as-regex-pattern-in-javascript and used it as seen above, but it made things worse.
I initially used:

str = str.replace('--','-');

but it stops at the first match. Any suggestions?

Would this be a number?

The basic replace will only replace the first instance found. You will need to use a regular expression with the global modifier or use replace with a function. I recommend trying a regular expression first. See the link below for
examples.

Yes. I console.logged it.

Why doesn’t the one I used (regdd) work? And also I found that the .replace has a “string” parameter in the function arguement which says that you can check the whole string


Can’t I use that?