Windows powershell tips:Conditional Operators
来源:互联网 发布:java支付接口开发 编辑:程序博客网 时间:2024/06/05 03:52
复习下 -match,-like,-contains
1. -match 用在 regular expression 去匹配 可以使用wildcard
example 1: 不是必须用在开头的匹配
$guy = "Guy Thomas 1949"
$guy - match “Th”
# Result PS> True
Example2: 一个错误的名字是不行的
$guy = "Guy Thomas 1949"
$guy - match “Guido”
# Result PS> False
Example3: 用wildcard ?
$Guy ="Guy Thomas 1949"
$Guy -Match "19?9"
# Result PS> True
Example4: 用wildcard *
Get-WmiObject -List | Where {$_.name -Match "cim*"}
Note:powershell recognized the following character classes:
\w : mathces any word character, meaning letters and mumbers
\s : matchs any space character,such as tab, space, and so for forth
\d : matches any digt charater
# PowerShell Character Class Example
$Guy ="Guy Thomas 1949"
$Guy -Match "\w"
# Result PS> True
=====================================================================
2. -like 是表达式两边必须是一样的, 可以使用wikdcard *
Example1: 只有一部分相同是不可以的
$Guy ="Guy Thomas 1949"
$Guy -Like "Th"
# Result PS> False
Example 2: 只有开始部分相同也是不可以的
$Guy ="Guy Thomas 1949"
$Guy -Like "Guy"
# Result PS> False
Example3:用通配符就可以$Guy ="Guy Thomas 1949"
$Guy -Like "Guy*"
Result PS> True
在-like 里面通配符是两边都可以用的
$Guy ="Guy Thomas 1949"
$Guy -Like "*Th*"
# Result PS> True
=========================================================================
3.- contains 它和-eq 有点像,除了返回值都是true或者false 外,-contains 是用在array,collection,hashtable 里面test 一个元素
Example1:检查each item between commas
# PowerShell -Contains
$name = "Guy Thomas", "Alicia Moss", "Jennifer Jones"
$name -Contains "Alicia Moss"
# Result PS> True
Exameple2: 要求元素精确匹配才行
# PowerShell -Contains
$name = "Guy Thomas", "Alicia Moss", "Jennifer Jones"
$name -Contains "Jones"
# Result PS> False
Exameple3:不可以使用wildcard
# PowerShell -Contains
$name = "Guy Thomas", "Alicia Moss", "Jennifer Jones"
$name -Contains "*Jones"
# Result PS> False
=============================================================================
总结:-conains 用在array,collection,hashtable 中test 元素的,不可以使用通配符,要元素完全一致才可以
-like 要表达式两边完全一摸一样,可以使用wildcard,前后都可以使用wildcard
-match 是用在string 的任何地方,也可以用通配符,只能后面用一个
- Windows powershell tips:Conditional Operators
- Stady notes: Windows powershell tips
- 14.11 Conditional logical operators
- 14.11 Conditional logical operators
- Learning note(1) for Windows PowerShell Tips
- Learning note(2) for windows powershell Tips
- Learning note(3) for Windows powershell Tips
- Learning note(4) for windows powershell Tips
- Learning note(5) for windows powershell Tips
- Learning note(6) for windows powershell Tips
- Learning note(7) for windows powershell Tips
- Learning note(8) for windows powershell Tips
- Windows PowerShell
- Windows powershell
- windows powershell
- windows powershell
- Stady notes: Windows powershell tips -Even More Things You Can Do With Arrays
- Windows Tips
- 简单记录,非常简单的一个提示音播放类(允许多个提示音播放)
- PL/SQL连接Oracle设置
- 每个程序员都应读的书
- PL/SQL编程(高级特性)
- 面试 改错题-1
- Windows powershell tips:Conditional Operators
- IOS开发(89)之动画之视图的缩放
- IOS开发 图片的上传和下载(关于编码问题)
- 数据库设计及建模工具——ERwin简介
- 编成技术27
- flex 连续播放图片
- oracle数组及案例分析
- Draw2D技术
- 计算机经典书籍推荐