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.