PowerShell: String Wildcards

By Xah Lee. Date: . Last updated: .

Wildcard can be used to represent string patterns. For example, dir "*jpg" means list any filename ending in jpg.

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