小编sim*_*mon的帖子

在powershell中获取文件名中正则表达式的索引

我正在尝试获取文件夹名称中正则表达式匹配的起始位置。

dir c:\test | where {$_.fullname.psiscontainer} | foreach {
$indexx = $_.fullname.Indexofany("[Ss]+[0-9]+[0-9]+[Ee]+[0-9]+[0-9]")
$thingsbeforeregexmatch.substring(0,$indexx)
}
Run Code Online (Sandbox Code Playgroud)

理想情况下,这应该可行,但由于 indexofany 不处理正则表达式,所以我陷入了困境。

regex powershell substring indexof

5
推荐指数
2
解决办法
1万
查看次数

标签 统计

indexof ×1

powershell ×1

regex ×1

substring ×1