Powershell Editing Strings in Array

You may do the following to output a new array of values without the domain names:

# starting array
$array = @("hosta.domain1.com", "hostb.domain2.com", "host3", "10.0.0.1")
# domains to remove
$domains = @('.domain1.com','.domain2.com')
# create regex expression with alternations: item1|item2|item3 etc.
# regex must escape literal . since dot has special meaning in regex
$regex = $domains.foreach{[regex]::Escape($_)} -join '|'

# replace domain strings and output everything else
$newArray = $array -replace $regex