如何在两个单词之间提取文本?我知道正则表达式可以做到这一点,我一直在环顾四周,但我尝试的代码根本不适合我......就像正则表达式的砖头一样无能为力......所以可能做错了......
我有一个文本文件,想查询这些文本字符串之间显示的任何内容:
[问题设备]
设备 PNP 设备 ID 错误代码
[USB]
我试过这样做,但无处可去!
$devices = Get-Content c:\temp\dev.txt | out-string [regex]::match($devices,'(?<=\<Problem Devices\>).+(?=\<USB\>)',"singleline").value.trim()
You cannot call a method on a null-valued expression.
At line:1 char:141
+ $devices = Get-Content c:\temp\dev.txt | out-string [regex]::match($devices,'(?<=\<Problem Devices\>).+(?=\<USB\>)',"
singleline").value.trim <<<< ()
+ CategoryInfo : InvalidOperation: (trim:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull