Reputation: 1167
I have a url http://www.mysharepointsite.sharepoint.com/sites/test
.
is there any easier what to get the /sites/test
than getting the 3rd slash and beyond?
and if not how can I get the position of the 3rd slash?
Upvotes: 2
Views: 134
Reputation: 58981
Yes, you can use the .NET System.Uri Class:
([System.Uri]'http://www.mysharepointsite.sharepoint.com/sites/test').PathAndQuery
# Output: /sites/test
And here is a example using regex:
$site = 'http://www.mysharepointsite.sharepoint.com/sites/test'
$regex = '(?:\/\/).*?(\/.*)'
[regex]::Match($site, $regex).Groups[1].Value
# Output: /sites/test
Upvotes: 3