Dollar sign meaning

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

I gather that the dollar sign in this expression refers back to ([a - z]) and ([A-Z]) respectively?

I have not had that syntax explained to me and I am wondering how and when this type of syntax can be used.

Here is the lesson regarding the syntax in question.
This things within prenthesis are called capture groups, items you can refer to. The dollar sign in this case, is a way to refer to the respective capture group.
The lesson shows very good example, on how you can swap the places of the capture groups in a string, or you could repeat the given capture group.

console.log("Code Camp".replace(/(\w+)\s(\w+)/, '$1 $1 $1'))
//Code Code Code

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