I think I've found a vague pattern, but it doesn't match your results.
You can name matched groups with (?<name>pattern) or (?'name'pattern)
Replace with ${name} doesn't work.
Replace with $n doesn't work.
Replace with \n does work.
I can't find any way of replacing via the matched group name so far. Using
$ in the replace always causes no changes with no clue why. Web searches
hint that everyone was advised to change from \n to $n to fix their
problems, but I found the reverse.
So if I use \n only as the replace and ignore naming groups it works.
Phew, Greg