For some reason, this answer I found for (supposedly) how to do it in php just gives me the wrong matches. It seems to add the dash, but also replace the capital letter wit
Try the following:
var result = "fooBarBaz".replace(/([A-Z])/g, "-$1").toLowerCase(); console.log(result);