regex - 使用indexof获取第三个斜杠

标签 regex powershell

我有一个网址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/

相关文章:

java - 将阿拉伯文本与正则表达式匹配

javascript - 正则表达式捕获尽可能多的 Javascript 重定向

python - 仅当找到多个模式时才匹配正则表达式(python)

function - 基本 Powershell 日志记录

powershell - 在脚本中动态设置 Azure DevOps 变量

arrays - PowerShell 结果数组重复输出

powershell - 使用 powershell 将全屏应用程序/游戏移动到辅助监视器

javascript - 删除新行,除非新行前面有双空格

javascript - 匹配任何字符后跟非数字

c# - 重命名文件Powershell看不到