Understanding this challenge ♥

Understanding this challenge ♥
0

#1

Hello everyone, i’m so confused about the “Spinal tap Case” Challenge, in the intermediate algorithms.

Here is where I have trouble in the code solution :

str = str.replace(/([a-z])([A-Z])/g, '$1 $2');

Why do we have to search for lowercase letters? why not only replacing the before of each capitalized letters by a whitespace?

And also why when we test the first char isn’t a blank space (since it should due to the [A-Z][a-z]) ?

I hope someone can help it took 3 days to this one and my code was so dirty that I looked for the clean solution …
I’m not good at regex I don’t know if it happen to some of you ?
Peace


#2

This regex looks for a lowercase char that is adjacent next to an uppercase. A good example is ‘thisIsSpinalTap’. Using the replace function, ’ $1 $2’ is telling to put a space between the lowercase and uppercase.

Here is an example
https://regex101.com/r/h7TcGx/1


#3

Oh right ! Adjacent ! I never thought about it !
And yeah after a good night i’m getting the $1 $2 meaning, thank’s a lot ! :slight_smile: