(. *) - will be a template to match any number of characters. The brackets will mark it as an additional template (for a backlink).
$ 2 and $ 1 are backlinks. These will be the things matching your second and first pattern.
Basically replaceAll ("(.) (.)", "$ 2, $ 1") will find characters separated by a space, then add a comma before the space, and also flip the parts. For instance:
ab => b, a Hello world => Hellw, oorld
Not sure about nesting ... Can you post the code you use?
source share