like 运算符

-like 接受 wildcard 匹配。

* 可以匹配任意数量的字符。

? 匹配任意字符之一。

[] 包含要匹配一次的字符范围。

# Matches 127.0.<anything>

Get-NetIPAddress | where IPAddress -like '127.0.*'

# Matches 127.0.0.<one character>

Get-NetIPAddress | where IPAddress -like '127.0.0.?'

# Matches 127.0.0.<one number between 0 and 9>

Get-NetIPAddress | where IPAddress -like '127.0.0.[0-9]'

match 运算符

-match 使用正则表达式。

这增加了更多的灵活性和复杂性。

. 可以匹配这里的任何字符,所以字面点应该用反斜杠转义。

# Matches 127.0.0.<one number between 0 and 9>

Get-NetIPAddress | where IPAddress -match '127\.0\.0\.[0-9]'

# Matches 127.<any number>.<any number>.<any number>

Get-NetIPAddress | where IPAddress -match '127\.[0-9]+\.[0-9]+\.[0-9]+'

# Matches 127.0.<one number between 0 and 9>.<two digit number>

Get-NetIPAddress | where IPAddress -match '127\.0\.[0-9]\.[0-9]{2}'


友情提示:本站所有文章,如无特殊说明或标注,均为何星星原创发布。与此同时,趋于近年来本站的文章内容频繁被他站盗用与机器采集,现已全局禁用网站文字内容操作,了解详情或转载文章请 点此 继续!

0 条评论

发表回复

Avatar placeholder

您的电子邮箱地址不会被公开。 必填项已用 * 标注