Help with spinal case

I know what to do.

  1. I need to split all words from underscoreCase or camelCase or reguler text to an array with help of regex.

  2. Then i need to join the array items to a string with one whitespace between each word.

  3. Afterwards the string should be converted to lowercase.

  4. And lastly i ned to replace the white space with dashes “-”.

But thing is i dont know how to make one regex that splits the words from camelCase, underscorCase text and a hybrid between those two.

Did you try this:

let regex1 = /[A-Z0-9][a-z0-9]/g;
let regex2 = /[^\s]/g;
let regex3 = /[^_]/g;
let combinedRegEx = new RegExp(`(${regex1})|(${regex2})|(${regex3})`);

I tried that but the match returned null.

Post your code, it is the only way in which we could help effectively

const spinalCase = str => {
    if (str.length < 0) {
        return null;

    else {
        const regex = /[A-Z0-9][a-z0-9]|[^\s]|[^_]/g;
        const words = str.match(regex);

spinalCase("This Is Spinal Tap");

I know how to do all of the steps i mentioned expect the first step, the step with regex.

Try debugging your code with this:

If you feel you are not able to create that regex, surely someone else did that before you, try searching for it using google (that is also an important part of the Read-Search-Ask method)