运行程序提取返回数据问题


0
panda123 asked 7 年 ago

用执行程序Start-Process -FilePath c:\123.exe -ArgumentList “-test” -NoNewWindow
输出数据
-----------------------
abcde
随机数据
asdfg
-----------------------
怎么用正则把abcde和asdfg中间的数据提取出来啊?

1 Answers
0
Best Answer
Mooser Lee 管理员 answered 7 年 ago

PowerShell 正则表达式中的组引用。
结果为字符串数组,把字符串数组合并成一个字符串,然后正则匹配。

$result=@(
"-----------------------",
"abcde",
"随机数据",
"asdfg",
"-----------------------"
)
$resultString = $result -join ''
$null= $resultString -match "abcde(?<keyinfo>.*?)asdfg"
$Matches.keyinfo