create a copy of your finished comp, hide all the layers you don’t need,
replace your floor and/or other shadowcatcher layers with a white layer, material options: Accepts Lights = ‘Off’
set your shadowcasting layer to Cast shadows = ‘only’
You’ll get a pure white environment with black shadows, you can multiply that render on top of other layers, or if you must, perform a luma key on that.
This works best if you’re using just 1 light.
If you use multiple lights, the other lights won’t interfere correctly,
eg. they won’t lighten the shadows (because of the accept lights = off).
Your best bet would then be to accept lights, though after compositing you will find that your floor and background layers can be a bit darker. (they’ve had their diffuse shading subtracted twice)
There are ways around that, but it get’s more complicated pretty soon.
Let me know if you’re missing the desired result (if you have mulitple lights) and I’ll outline a step by step for the more complicated way.