我有一个网址http://www.mysharepointsite.sharepoint.com/sites/test
。
有什么比获取第三个斜杠及其他斜杠更容易获取 /sites/test
的内容吗?
如果不是,我怎样才能得到第三个斜杠的位置?
最佳答案
是的,您可以使用.NET System.Uri类(class):
([System.Uri]'http://www.mysharepointsite.sharepoint.com/sites/test').PathAndQuery
# Output: /sites/test
这是一个使用正则表达式的示例:
$site = 'http://www.mysharepointsite.sharepoint.com/sites/test'
$regex = '(?:\/\/).*?(\/.*)'
[regex]::Match($site, $regex).Groups[1].Value
# Output: /sites/test
关于regex - 使用indexof获取第三个斜杠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31760473/