Problematic test case while spliting strings

Hello campers,

I am trying to solve this exercise: Split a String into an Array Using the split Method

Link to the challenge:

This is my code. I am almost there!

function splitify(str) {
// Only change code below this line

let newStr = str;
let splitedStr = newStr.split(/\s|,|-/);
return splitedStr
// Only change code above this line
console.log(splitify("Hello World,I-am code"));

My browser information:

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0.

Unfortunately, my regex code is not passing on this final test:

splitify("") should return ["This", "is", "a", "sentence"]

The is the problem. I know other ways to solve this. However, I would like to build upon this regex: split(/\s|,|-/)

Is it possible to solve the challenge with something on top of this?

Thanks in advance.


I think you just need to split on period (".") as well.
Maybe something like this?
Add the backslash, otherwise it’ll be interpreted as the wildcard symbol

    let splitedStr = newStr.split(/\s|,|-|\./);
1 Like


I was missing the backslash. Thanks!

1 Like