The idea of this function is to turn camelCase into spinal-case by using regex capture groups to capture the capital letters, make the modifications and then reinsert them. The capture group works but the replacement function does not and I'm beginning to get regex migraines.
function spinalCase(str) {
var regexp = /([A-Z]{1})/g;
var match;
var matches = "";
var myRegexp;
while ((match = regexp.exec(str)) != null) {
matches = "-" + match[1].toLowerCase();
//matches = "t", "i", "s", "t"
myRegexp = new RegExp(match[1], "g");
str.replace(myRegexp, matches);
}
return str;
//returns the original string without modifications
}
console.log(spinalCase('ThisIsSpinalTap'));