Excel/Powershell to extract substring from a URL

I want to extract root URL from full URL. how to extract that based on number of “/” in that.

for example:

https://teams.SharePoint.com/sites/site/communities/subsite 

from this URL i want to extract below root site(string before 5th “/”).

https://teams.SharePoint.com/sites/site 

Please assist how to achieve this in Powershell and in excel.