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

Check the stack of opened constructs for groups when emit back-refs.
Merge pull request #2170 from DmitryOlshansky/issue-12747

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