Fix issue 12747 std.regex bug in the parser allows reference to open gro...

...ups.

Check the stack of opened constructs for groups when emit back-refs.