Home > Back-end >  I have a small problem with the (if) command in PowerShell
I have a small problem with the (if) command in PowerShell

Time:11-08

First, I will show my project

$url = Read-Host 'URL'
if ( $url -notmatch '\.'){
    msg * "The title does not contain(.)"
}

Explanation of the code

The code should alert you that the site does not have a .

The problem is that the code alerts you if the link contains a . Once, I want him to alert me if he finds it. twice

Example:

$url = Read-Host 'URL'
if ( $url -notmatch '\.' = 2){
    msg * "The title does not contain(.)"
}

CodePudding user response:

= is an assignment and not an operator for equality.

If you want the given url to have at least 2 dots in it, try

$url = Read-Host 'URL'
if ( [regex]::matches($Url, '\.').Count -lt 2 ){
    msg * "The url does not contain 2 dots (.)"
}
  • Related