![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest
Posts: n/a
| Select-String pattern quirk??? the -pattern in select string specifies the string or regular expression that represents the matching criteria. when i try to search for "$hay": "$hay bla bla" | select-string -pattern "$hay" it returns an error Select-String : Cannot bind argument to parameter 'Pattern' because it is an empty string. At line:1 char:34 + "$hay bla bla" | select-string <<<< "$hay" when escaping the $ sign: "$hay bla bla" | select-string -pattern "\$hay" it returns an error Select-String : parsing "\" - Illegal \ at end of pattern. At line:1 char:34 + "$hay bla bla" | select-string <<<< "\$hay" just to be sure on regex pattern, i tried "$hay bla bla" -match "$hay" and it returns true without escaping the $ sign. i guess the $ sign is the trouble maker. any suggestions? -- $hay http://scriptolog.blogspot.com |
| | #2 (permalink) |
| Guest
Posts: n/a
| Re: Select-String pattern quirk??? "$hay" <no@addre.ss> wrote in message news:eff9Gm9OHHA.5000@TK2MSFTNGP03.phx.gbl... > "$hay bla bla" -match "$hay" > > and it returns true without escaping the $ sign. > > i guess the $ sign is the trouble maker. any suggestions? Yep. Try this: '$hay bla bla' | select-string -pattern '\$hay' The single quotes turn off PoSh's variable expansion. Then you need to escape the $ in the regex because that is the end-of-line marker. -- Keith |
| | #3 (permalink) |
| Guest
Posts: n/a
| RE: Select-String pattern quirk??? Note that you have 2 ways of escaping here (PowerShell / backtick) and regex : you can use single quotes or escape them (powerShell backtick ) examples : PS H:\> '$hay bla bla' | select-string -pattern '$hay' PS H:\> '$hay bla bla' | select-string -pattern '\$hay' $hay bla bla PS H:\> "`$hay bla bla" | select-string -pattern '\$hay' $hay bla bla PS H:\> "`$hay bla bla" | select-string -pattern "\`$hay" $hay bla bla "$hay" wrote: > the -pattern in select string specifies the string or regular expression > that represents the matching criteria. > > when i try to search for "$hay": > > "$hay bla bla" | select-string -pattern "$hay" > > it returns an error > > Select-String : Cannot bind argument to parameter 'Pattern' because it is an > empty string. > At line:1 char:34 > + "$hay bla bla" | select-string <<<< "$hay" > > when escaping the $ sign: > > "$hay bla bla" | select-string -pattern "\$hay" > > it returns an error > > Select-String : parsing "\" - Illegal \ at end of pattern. > At line:1 char:34 > + "$hay bla bla" | select-string <<<< "\$hay" > > just to be sure on regex pattern, i tried > > "$hay bla bla" -match "$hay" > > and it returns true without escaping the $ sign. > > i guess the $ sign is the trouble maker. any suggestions? > > -- > $hay > http://scriptolog.blogspot.com > > > > |
| | #4 (permalink) |
| Guest
Posts: n/a
| Re: Select-String pattern quirk??? Thanks Keith and Mow, this resolves everything $hay http://scriptolog.blogspot.com "$hay" <no@addre.ss> wrote in message news:eff9Gm9OHHA.5000@TK2MSFTNGP03.phx.gbl... > the -pattern in select string specifies the string or regular expression > that represents the matching criteria. > > when i try to search for "$hay": > > "$hay bla bla" | select-string -pattern "$hay" > > it returns an error > > Select-String : Cannot bind argument to parameter 'Pattern' because it is > an empty string. > At line:1 char:34 > + "$hay bla bla" | select-string <<<< "$hay" > > when escaping the $ sign: > > "$hay bla bla" | select-string -pattern "\$hay" > > it returns an error > > Select-String : parsing "\" - Illegal \ at end of pattern. > At line:1 char:34 > + "$hay bla bla" | select-string <<<< "\$hay" > > just to be sure on regex pattern, i tried > > "$hay bla bla" -match "$hay" > > and it returns true without escaping the $ sign. > > i guess the $ sign is the trouble maker. any suggestions? > > -- > $hay > http://scriptolog.blogspot.com > > > |
| |
| |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| problems with $var | select-string -pattern $string -q | Ben Christian | PowerShell | 3 | 02-08-2008 12:41 PM |
| Select-String problem | Keith Hill [MVP] | PowerShell | 3 | 06-17-2007 12:18 PM |
| Re: select-string exceptions | cmyers | PowerShell | 0 | 05-23-2007 02:09 PM |
| Re: select-string exceptions | cmyers | PowerShell | 0 | 05-23-2007 02:09 PM |
| select-string to act like grep -v | Frank | PowerShell | 5 | 05-12-2007 12:59 AM |