View Single Post
Old 08-18-2008   #4 (permalink)
Shay Levy [MVP]


 
 

Re: Powershell Operator

Hi AdityaKir,

When you don't know what regex meta characters your variable might contain,
there is a great method to *auto*
escape them:


PS > $check = "Microsoft(R) Windows(R) Server 2003*"
PS > $escaped = [regex]::escape($check)
Microsoft\(R\)\ Windows\(R\)\ Server\ 2003\*


---
Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic



A> hi,
A>
A> I need to do some string comparison but the below script doesnt seem
A> to return true
A>
A> $version = "Microsoft(R) Windows(R) Server 2003, Enterprise Edition"
A> $check = "Microsoft(R) Windows(R) Server 2003*"
A>
A> I am checking if the $Check exists in $Version
A>
A> $Version -match $check
A>
A> Returns False. Should it return true. Using -Like works dont know why
A> ?
A>


My System SpecsSystem Spec