I'm not real good with regex, but I enjoy a challenge. I got this Powershell code to work.
$src = @("INFRA : Memory monitor on 172.16.0.1 - SERVER1 78% avg",
"INFRA : CPU monitor on 172.16.0.2 - SERVER2 100% used",
"INFRA : Disk space on 172.16.0.3 - SERVER3"
)
foreach ($line in $src) {
if ($line -match '(?:(CPU monitor on).*(?:- ))(.*?(?=\s))') {
"I found this line......: {0}" -f $line
"And this server name...: {0}" -f $matches[2]
$matches
}
}