Spinal Tap Case regex errors

Tell us what’s happening:
Hi, guys. I’m trying to find all the capitals letters that are not at the beginning of the string, and are joined to the previous word without whitespace. I plan to insert whitespaces in front of them for later transform. Here I tried to use noncapture groups to select all capital letters that have lowercase letters before them, but the console returned null. Earlier I tried to use lookbehind from ES2018 in the same way, and the result remains null. Can someone tell me if I’m logically wrong or if there are syntax errors? Thanks

Your code so far

function spinalCase(str) {
  // "It's such a fine line between stupid, and clever."
  // --David St. Hubbins
  let findCapitals = str.match(/(?:[a-z])([A-Z])/);
  return str;

spinalCase('This Is Spinal Tap');

Your browser information:

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

Link to the challenge:

Here’s what I get in the console when I run the tests:

  • null (for the call in the editor, with ‘This Is Spinal Tap’)
  • null (for the first test with “This Is Spinal Tap”)
  • [“sI”, “I”] (for test 2 with “thisIsSpinalTap”)
  • 2 more nulls for tests 3 and 4
  • [“lT”, “T”] (for test 5 with “AllThe-small Things”)

It seems to work fine, except it only finds the first occurrence. You’ll need to set the g flag.

I’m not sure how you’re going to insert white spaces in the right place though, since you get the letters, not their index. I’d just use split() with a regular expression. You don’t need to check what is before the capital letter, just split before any capital letter.