Powershell - Regular Expression Multiple Matches
问题 Maybe my reasoning is faulty, but I can't get this working. Here's my regex: (Device\s#\d(\n.*)*?(?=\n\s*Device\s#|\Z)) Try it: http://regex101.com/r/jQ6uC8/6 $getdevice is the input string. I'm getting this string from the Stream/Output from a command line tool. $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 Output: Device #0 Device #1