且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用正则表达式和 Powershell 从字符串中提取特定数据

更新时间:2022-11-12 08:44:40

又快又脏:

$found = $string -match '.*spid="(\d+)".*'
if ($found) {
    $spid = $matches[1]
}

其中 $string 是您上面提到的字符串.这将匹配任何具有 spid="somenumberhere" 的字符串,并将数字组合成一个匹配的组,您可以使用 $matches[1] 提取该组.

where $string is your above mentioned string. This would match any string that has spid="somenumberhere", and make the number into a matched group, which you can extract using $matches[1].