Without seeing an example what's in your "results variable" it's not possible to accurately answer your question. Your goal is also unclear. Are you simply trying to extract every occurrence of that pattern regardless of the IP addresses, or are you trying to extract the IP address from the first occurrence of that pattern and then use the extracted IP address to search the rest of the contents of the "results variable"? Or does "the first occurrence" mean the pattern must appear on the first object found in the "results variable"?
Here are two variations:
$x = "NTP(1.134.56.189:123,unicast)", "HTTP(23.235.124.2:80,xxx)", "SMTP(210.24.222.6:25,yyy)","NTP(62.65.87.100:123,unicast,zzz)","NTP(1.134.56.189:123,unicast)"
# look for pattern regardless of IP address
"Look for all"
$x |
ForEach-Object{
if ($_ -match "(NTP)\((\d\d?\d?\.\d\d?\d?\.\d\d?\d?\.\d\d?\d?):"){
"{0} {1}" -f $matches[1], $matches[2]
}
}
# get IP from 1st item, then search for that
"Look for first"
$lookforthis = ""
if ($x[0] -match "(NTP)\((\d\d?\d?\.\d\d?\d?\.\d\d?\d?\.\d\d?\d?):"){
$lookforthis = [regex]::Escape($matches[2])
$x |
ForEach-Object{
if ($_ -match "(NTP)\(($lookforthis):"){
"{0} {1}" -f $matches[1], $matches[2]
}
}
}