What does the \\1 do?
For example
\"foo bar bag\".gsub(/(bar)/,\'car\\1\')
I believe it has something to do with how you use parenthese
The \1 is syntax for the last capture in a regular expression using the () like you said. It says whatever was matched, replace it with that.
\1
()
You can continually use () groups and their respective \2 to continue to replace what you matched.
\2