Im my mind I can’t lowerCase before the regex, because I lose the reference to add "- " before the CAPS letters.
Any ideias?
Your code so far
js
function spinalCase(str) {
// "It's such a fine line between stupid, and clever."
// --David St. Hubbins
return str.trim().replace(/\s|_|(?=[A-Z])/g, "-").toLowerCase()
}
spinalCase('This Is Spinal Tap');
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36.
your regex capture both the space and the upper case letter, so if you have a space followed by a upper case letter, both will get the dash. I think you could change the look ahead to capture something only if it is not preceded by a space.
or add a look behind that will check of the upper case letter is preceded by an other letter, so you can also fix the dash at the beginning