Try something like this:
Pattern: (?<!\\)([$]+)([^$]*?)\\([^$]*?)(?<!\\)\1
Substitution: \1\2\\\\\\\\\3\1
Examples using your provided tests: https://regex101.com/r/X9lGCF/2
Rough explanation of pattern:
(?<!\\)([$]+) - Match and capture at least one unescaped $; the (?<!\\) is a negative lookbehind to make sure the $'s aren't prefixed with a backslash
([^$]*?)\\([^$]*?) - Capture the text between the first matched $ sequence and the same initially matched $ sequence on either side of the \\
(?<!\\)\1 - Reuse the initially matched $ sequence in our pattern (this enforces the surrounding $ sequences to be the same length; e.g. not matching things like $\\$$), ensuring that the last sequence is also unescaped
The substitution will replace the backslashes (they're escaped, hence why we use 8 of them to get 4 backslashes) with the surrounding captured text and $ sequences.