'How can I access different wildcard sin a nested match in Firebase Security Rules?

If I have a nested match, can I access previous wildcards? In the code below, can I somehow access {nameId} from the innermost match of match /userPosts/{postId}/ ? And if so, how do I differentiate between {nameId} and {postId} ?

match /general/exercises {
      allow read, write: if false;

      match /exerciseNames/{nameId} {
        allow read, write: if true;

        match /userPosts/{postId} {
          allow read: if true;
          allow create: if true;
          allow delete, update: if (resource.data == request.auth.uid); // if the request is that of the doc owner uid, then allow delete, update
        }

Or, how about this situation if the nest is not nested?

match /general/exercises {
      allow read, write: if false;

      match /exerciseNames/{nameId}/userPosts/{postId} {
        allow read, write: if true;
        allow delete, update: if (resource.data == request.auth.uid); // if the request is that of the doc owner uid, then allow delete, update
        }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source