gpt4 book ai didi

regex - PowerShell RegEx:从字符串获取SID

转载 作者:行者123 更新时间:2023-12-02 06:46:54 25 4
gpt4 key购买 nike

我正在尝试运行powershell命令以从字符串返回SID。

$string = "The SID is S-1-9-1551374245-3853148685-361627209-2951783729-4075502353-0-0-0-0-3"

Select-String -Pattern "\bS-\d{1}-\d{1}-\d{10}-\d{10}-\d{9}-\d{10}-\d{10}-\d{1}-\d{1}-\d{1}-\d{1}-\d{1}\b" -InputObject $string

当我运行上面的代码时,它返回整个字符串,但是我只想要SID#,即S-1-9-1551374245-3853148685-361627209-2951783729-4075502353-0-0-0-0-3'

最佳答案

$Pattern = 'S-\d-(?:\d+-){1,14}\d+'
$Matches = Select-String -Pattern $Pattern -InputObject $string
if ( $Matches ) { $Matches.Matches.Value }

归功于 vs97's regex pattern

关于regex - PowerShell RegEx:从字符串获取SID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58036023/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com