(#11133) If a node definition uses a regex, make its capture variables available in the node's scope

Please note, this commit is incomplete.

It has no tests yet, as I am unclear that I've fixed the bug in the best place, and without side-effects.