views:

45

answers:

1

I have a table in my database that includes some columns that are used for LIKE expressions in SQL. The process I'm working with uses those expressions to exclude certain SQL objects from processing.

I'm now putting similar code in Powershell, but I'd like to keep the columns consistent. I'm going to need to do something along the lines of:

where {$someVariable -like $myColumnData}

Is there any way to change a SQL LIKE expression into a Powershell -like expression? I might be able to write my own, but this seems like it would be tricky and error-prone, so if someone has already done the work, that would be great.

As an example, I'd like to be able to do conversions like the following:

%some string%    -->    *some string*
[0-9]blah%       -->    <I don't know what would go here>blah%

As a side-question, does the Powershell -like allow any standard regex expression or is it limited to ? and * wildcards?

Thanks!

A: 

It's the same. Take a look here, at wildcard characters for powershell: http://msdn.microsoft.com/en-us/library/aa717088(VS.85).aspx

Vidar Nordnes
I don't see anything on the linked page that allows for the use of % as a wildcard. I'll try testing it.
Tom H.
You did %some string% -> *some string*, so I thought you already had that one.[0-9]blah*
Vidar Nordnes
So it looks like "[]" is taken care of. Escape characters could still be a problem though.
Tom H.