Can you explain me this code?

Tell us what’s happening:
//I found this code in the solution. what is the use of $1 and $2?
str.replace(/([a-z])([A-Z])/g, “$1 $2”);

Your code so far

function spinalCase(str) {
console.log(str.replaceAll("_"," ").split(" ").join("-"))

spinalCase('This Is Spinal Tap');
spinalCase("Teletubbies say Eh-oh");

Your browser information:

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

Challenge: Spinal Tap Case

Link to the challenge:

$1 is what is captured in the first set of parenthesis. $2 is what was captured in the second set of parenthesis and so on.

1 Like