Spinal Tap Case, regex w/ split()

I’m using a regex with split() to create an array from a string. When I run this, the words in my array are missing their first letters and the spaces are being made into array values ex. ,he,ndy,riffith,how.

function spinalCase(str) {
// regex should find a capitol letter or underscore or whitespace
  let regex = /[A-Z]|\_|\s/g;

  let arr = str.split(regex);


I didn’t have much trouble with previous challenges that included regexes so this is disheartening. Googling hasn’t helped. Help! Thanks!

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make easier to read.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

Note: Backticks are not single quotes.


Thanks. I deleted those by accident, trying to be concise.

I was able to solve my issue with ?=. :slight_smile: