Poweshell escaped wildcard

8,686

You don't actually want to escape your wildcard character. Because then you just end up comparing to the wildcard character, while what you want to do is find out if your string contains an asterisk.

The way to do this is by matching on a regular expression.

'www.website.*' -match '\*'
Share:
8,686

Related videos on Youtube

Miquel Àngel
Author by

Miquel Àngel

Updated on September 18, 2022

Comments

  • Miquel Àngel
    Miquel Àngel over 1 year

    I'm trying to compare string which contains wildcard character.

    ("www.mysite.*" -match '`*')  
    

    But something is not working because I always get a True response, for example

    ("www.mysite.com" -match '`*') 
    

    I've tried using -contains instead, but i get always false.

  • Reaces
    Reaces almost 9 years
    @MiquelÀngel I'll probably be needing to use this in the future as well so looking it up was quite useful, thanks for the question!