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://
I used your sample data in a here-string for my testing. This should work although it can depend on where your sample data comes from.
Using powershell 3.0 I have the following
$getdevice |
select-string -pattern '(?smi)(Device\s#\d+?(.*?)*?(?=Device\s#|\Z))' -AllMatches |
ForEach-Object {$_.Matches} |
ForEach-Object {$_.Value}
or if your PowerShell Verison supports it...
($getdevice | select-string -pattern '(?smi)(Device\s#\d+?(.*?)*?(?=Device\s#|\Z))' -AllMatches).Matches.Value
Which returns 4 objects with their device id's. I don't know if you wanted those or not but the regex can be modified with lookarounds if you don't need those. I updated the regex to account for device id with more that one digit as well in case that happens.
The modifiers that I used
smodifier: single line. Dot matches newline charactersmmodifier: multi-line. Causes ^ and $ to match the begin/end of each line (not only begin/end of string)imodifier: insensitive. Case insensitive match (ignores case of [a-zA-Z])
Another regex pattern thats works in this way that is shorter
'(?smi)(Device\s#).*?(?=Device\s#|\Z)'