I suck at regular expressions ;(

Tell us what’s happening:

Your code so far

function spinalCase(str) {
return str
.replace(/([a-z])([A-Z])/g, '$1 $2')
.replace(/\s+_*\s*|_+\s*_*/g, '-')

console.log(spinalCase('This_ _ _   _ _ IsSpinalTap'));
//logs: this----is-spinal-tap.
//I know the code passes all the tests and that I can just
//continue adding \s* and _* but how can you make it work
//for any amount of spaces and underscores combined? 

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36.

Challenge: Spinal Tap Case

Link to the challenge:

Hello there,

You almost have everything you need. Here are some hints:

  • There are 2 cases to watch out for:
    • A non-[A-z] surrounded by _ or [A-z]
    • A lowercase letter followed by an uppercase letter
  • You need to only match either:
    • Spaces between a lowercase and uppercase
    • Non-[A-z]

I hope that helps somewhat.

Click for spoiler