How can I programmatically extract the site path from a given URL? The solution would have to be able to handle paths with multiple levels of sub sites. The number of sub site levels is also not always the same.
Here are two sample urls/examples and what I would like to get from them.
This one is two sub sites deep from the root site collection:
And one that is only one sub site deep: