Tiago Peczenyj is correct, and you need to handle both backlinks, capture groups, and named groups. Named groups, because in Java RegEx there is no restriction that a named group needs to return a link by name, it can be returned by number, like any other capture group.
If anyone is interested in a Java solution, I have implemented a library to do just that. https://github.com/vsch/reverse-regex .
Handles all valid regex Java constructors and provides utility classes for wrapping, matching, and input for reverse lookups to handle all the necessary mappings and calls.
source share