Split() not working

Tell us what’s happening:
this is my take on the problem. i have successfully passed 3/4. the only thing messing up my solution is that extra white space after ‘telebubbles’. how do i progress further? i’m not good with replace

  **Your code so far**

function spinalCase(str) {
let k=str.split(/[\s-_]?(?=[A-Z])/g).join('-').toLowerCase()
return k

spinalCase('This Is Spinal Tap');//passed
spinalCase("Teletubbies say Eh-oh")//not working
spinalCase("AllThe-small Things")//passed
  **Your browser information:**

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36

Challenge: Spinal Tap Case

Link to the challenge:

you split only if there is an uppercase letter, you need to split also if after the space there is a lowercase letter

1 Like

after doing (?=[A-Z\s]) i’m not getting the required result

Hi @shahid.alam57,

Try using the below regular expression along with the join and lowercase method.


Split the string at one of the following conditions ( converted to an array )

  • a whitespace character [ \s ] is encountered
  • underscore character [ _ ] is encountered
  • or is followed by an uppercase letter [ (?=[A-Z]) ]

I hope this helps

1 Like

then whats the difference between the logical OR and square brackets?

won’t it be better to take “white-space, underscore AND capital letters” instead of “white-space OR underscare OR capital letters”?

Hi @shahid.alam57

Here is the difference between OR and square bracket

  • (a|b|c) is a regex “OR” and means “a or b or c”.

  • [abc] is a “character class” that means “any character from a,b or c” (a character class may use ranges, e.g. [a-d] = [abcd] )

I hope this helps


i see. so the square bracket acts as a range setter?

Yes, Exactly. That’s the major difference between them.

1 Like

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