Powershell 正则表达式提取字符串中的设备实例 ID - ROOT\VMWARE\0000
使用以下代码来实现:\n\npowershell\n$text = "驱动程序管理结束了为设备添加服务 VMnetAdapter 的过程,设备实例 ID 为 ROOT\VMWARE\0000,返回的状态值为"\n$pattern = 'ROOT\\VMWARE\\[0-9]+'\n$match = [regex]::Match($text, $pattern)\nif ($match.Success) {\n $result = $match.Value\n Write-Output $result\n} else {\n Write-Output "No match found." \n}\n\n\n这段代码首先定义了要匹配的字符串 $text,然后使用正则表达式模式 $pattern 来匹配字符串中的 ROOT\VMWARE\0000。接下来使用 [regex]::Match 方法对 $text 进行匹配,如果匹配成功,则将匹配到的结果保存在 $result 变量中,并使用 Write-Output 输出结果。如果没有匹配到,则输出 "No match found."。
原文地址: https://www.cveoy.top/t/topic/pHYv 著作权归作者所有。请勿转载和采集!