This week I remembered vim(8) can group regular expressions.

For example, the command :%s/\(foo\)/\1bar/g will replace all occurences of foo with foobar.

:help /\1 and :help pattern.txt have a lot more information.