Stuck on my first step

Tell us what’s happening:
Describe your issue in detail here.
My intention is to use regex to eliminate stray spaces and punctuation marks. That would get all the test cases to an even playing field and I could figure out what to do from there.

However, I can’t get rid of this pesky dash and I thought that \W and \s would indicate sequences where there is a non-alphanumeric character(i.e. ‘-’) after a series of alphabet characters (\w+). This isn’t happening and I must be misunderstanding the regex (or something else?).

Regardless, I need some help.

   **Your code so far**

function spinalCase(str) {


 //remove non-space characters and space characters occuring after a series of alphabetic characters, replace only alphabetic characters

let result = str.replace(/^\w+\s$/gi, /[a-z]/gi);
 
console.log(result);
 

 


 return result;
}

spinalCase("AllThe-small Things");
   **Your browser information:**

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

Challenge: Spinal Tap Case

Link to the challenge:

This regex /^\w+\s$/gi reads as: from the beginning (^) match alphanumeric characters plus underscore (\w) one or multiple times (+) followed by space (\s) which is at the end of the string ($). Search globally (g), ignoring case (i).

So "AllThe-small Things" doesn’t match. But "AllThe_small " would.

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