我在PowerShell中的(if)命令有一个小问题



首先,我将显示我的项目

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

代码说明

该代码应提醒您该站点没有.

问题是,如果链接包含.,代码会提醒你。有一次,如果他发现它是.,我希望他提醒我两次

示例(伪代码(:

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

=是一个赋值,而不是相等运算符。

如果您希望给定的url中至少有2个点,请尝试

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

相关内容

最新更新