You can extract specific text using split()
method in PowerShell.
$txt = "www.google.com"
$txt.Split(".")
Split()
return an Array and the first element is www
. So if you want to return google
write the following:
$y = $txt.Split(".")[1]
Another example
$email = "mail@gmail.com"
$x = $email.Split("@")
$domain = $x[1]
$domain = $domain.Split(".")[0]
Write-Host "email: " $email
Write-Host "Domain: " $domain
Output:
email: mail@gmail.com
Domain: gmail