extracting near clip distance and others from projection matrix

I’m trying to calculate the near clipping distance that was used to generate the projection matrix. I’d like to be able to compute this distance either on the CPU or in a vertex shader to be sent to a fragment shader. I’ve done some searching and found a few things that show me that it should be possible, but the math is too complex for me to figure out. I’m just not sure how to go about solving a matrix for one of the parameters used to create it.

Another problem I am envisioning is to reliably extract the near distance in both perspective and orthographic projections using the same equation, because I’ve found that the way they are constructed is different.

I’m sure someone here is better at matrix math than I am?