也许我的推理是错误的,但我不能让这个工作.
这是我的正则表达式: (Device\s#\d(\n.*)*?(?=\n\s*Device\s#|\Z))
试试看:http://regex101.com/r/jQ6uC8/6
$getdevice是输入字符串.我从命令行工具的Stream/Output中获取此字符串.
$dstate = $getdevice |
select-string -pattern '(Device\s#\d(\n.*)*?(?=\n\s*SSD\s+|\Z))' -AllMatches |
% { $_ -match '(Device\s#\d(\n.*)*?(?=\n\s*SSD\s+|\Z))' > $null; $matches[0] }
Write-Host $dstate
Run Code Online (Sandbox Code Playgroud)
输出:
设备#0设备#1设备#2设备#3设备#4
$ matches [1]的输出相同,$ matches [2]为空.
有没有办法可以获得所有比赛,比如regex101.com?我正在尝试将输出/字符串拆分为单独的变量(一个用于Device0,一个用于Device1,Device2,依此类推).
更新:这是命令行工具的输出:http://pastebin.com/BaywGtFE
如何让以下文本的输出仅显示引号中的文本(不带引号)?
示例文本”
this is an "apple". it is red
this is an "orange". it is orange
this is an "blood orange". it is reddish
Run Code Online (Sandbox Code Playgroud)
变成:
apple
orange
blood orange
Run Code Online (Sandbox Code Playgroud)
理想情况下,如果可能的话,我想在一个班轮中进行。我认为这是带有 -match 的正则表达式,但我不确定。