我想从这个字符串中提取
blocked-process-report process id="process435d948" taskpriority="0" logused="0" waitresource="RID: 7:1:1132932:0" waittime= "3962166" ownerId="4641198" transactionname="SELECT" lasttranstarted="2011-09-13T17:21:54.950" XDES="0x80c5f060" lockMode="S" schedulerid="4" kpid="18444" status="susp ended" spid="58" sbid="0" ecid="0"
该值以粗体显示,但仅包含值或58。该值可以具有不同的值,有时为80或1000,以此类推,但始终> 50。
我该如何使用regex和posh做到这一点?
最佳答案
快速而肮脏:
$found = $string -match '.*spid="(\d+)".*'
if ($found) {
$spid = $matches[1]
}
其中
$string
是您上面提到的字符串。这将匹配任何具有spid =“somenumberhere”的字符串,并将数字分成一个匹配的组,您可以使用$matches[1]
进行提取。
关于regex - 使用正则表达式和Powershell从字符串中提取特定数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7409133/