我正在尝试运行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/

10-16 20:43