PowerShell: String Wildcards
Wildcard can be used to represent string patterns.
For example, dir "*jpg"
means list any filename ending in jpg.
- Most command's
Path
parameter value is interpreted as wildcard pattern. e.g.dir *.jpg
lists only files whose name ends in.jpg
. - If you don't want wildcard, use the
LiteralPath
parameter.
Wildcard Syntax
?
-
Match any character.
*
-
Match any character, zero or more times.
[a-z]
-
Match a range of characters a to z.
[chars]
-
Match any char in chars
Operator for String Match Wildcard
str -like wildcard
-
return True if str match wildcard. else False. Case-insensitive
〔see PowerShell: True, False (boolean)〕
"mycat.jpg" -like "*jpg" # True # the wildcard must be on right side
-iLike
-
Case-insensitive. Same as
-Like
. -cLike
-
Case-sensitive
-notLike
-
Negation.
-iNotLike
-
Case-insensitive. Same as
-NotLike
. -cNotLike
-
Case-sensitive
PowerShell String
- PowerShell: Quote String
- PowerShell: Double Quoted String, String Expansion
- PowerShell: Here-String
- PowerShell: Escape Characters
- PowerShell: String Operators
- PowerShell: Join String
- PowerShell: Split String
- PowerShell: Format String
- PowerShell: String Methods
- PowerShell: String Wildcards
- PowerShell: Regular Expression Operators
- PowerShell: Regular Expression Syntax