Please I don't know why other strings aren't passing the challenge

Tell us what’s happening:
Describe your issue in detail here.

 **Your code so far**
 I think something is missing inside my regular expression let regEx = /[A-Z\s_]/g;, Please can anyone help ? 

function spinalCase(str) {
let regEx = /[A-Z\s_]/g;
 let newStr = str.toLowerCase();
 // return newStr.split(regEx).join("-")
 return newStr.replace(regEx, "-");
}

console.log(spinalCase('thisIsSpinalTap'));
 **Your browser information:**

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

Challenge: Spinal Tap Case

Link to the challenge:

With your regex, you’d end up with this-s-pinal-ap - you’re replacing the capital letters with hyphens.

This might be a good place to look at capture groups in your regex.

It works perfectly for “This Is Spinal Tap”, but didn’t work for this ‘thisIsSpinalTap’ , instead same string was outputed.

The regEx you are creating is looking for uppercase letters but on the very next line you are converting the entire string to lowercase so when you use regEx there will never be any uppercase letters to match on.

Also, using your regEx to replace an upper case letter with - doesn’t make sense since you don’t want to replace existing letters with a -.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.