PowerShell: String Wildcards

By Xah Lee. Date: . Last updated: .

Wildcard represents string patterns. e.g. *jpg means text 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
"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 and regular expression