Matching "Stars"

by May 30, 2012

Asterisk serve as wildcards, so how would you check for the presence of an asterisk? It's much harder than you might think:

PS> 'Test*' -eq '*'
False
PS> 'Test*' -like '**'
False
PS> 'Test' -like '**'
False

None of those work. Regular expressions do:

PS> 'Test*' -match '\*'
False
PS> 'Test' -match '\*'
False

Twitter This Tip! ReTweet this Tip!