Why [a-z][A-Z] in Spinal Tab Case?

Hi, friends! I wanted to ask why do we use /([a-z])([A-Z])/g instead of (/(\w)/g);
Is this because w accepts numbers and includes underscores?

function spinalCase(str) {
// Create a variable for the white space and underscores.
var regex = /\s+|_+/g;

// Replace low-upper case to low-space-uppercase
str = str.replace(/([a-z])([A-Z])/g, "$1 $2");

// Replace space and underscore with -
return str.replace(regex, "-").toLowerCase();

// test here

console.log(spinalCase('This Is Spinal Tap'));
console.log(spinalCase("Teletubbies say Eh-oh"));
console.log(spinalCase("AllThe-small Things"));

Challenge: Spinal Tap Case

Link to the challenge:

[a-z][A-Z] is a lowercase letter followed by an uppercase letter. \w+ is one or more word characters. They mean different things.

1 Like

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