Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - $Variables into Regular expressions ?! help

Reply
 
Old 05-07-2009   #1 (permalink)
rush


 
 

$Variables into Regular expressions ?! help

I've got a requirement to find a string in an array.
Simple! but I need to search on the string contained in 2 variables,

So basically I'm trying.

$SearchStr ="$SuppliedStr1*$SuppliedStr2"
$RegStr=[regex] $SearchStr

$ArrayToSearch | where { $_ -match $RegStr }

This appears to work OK, BUT I need to match where $SuppliedStr2 in
the End of the line in the array, so I guess I'm trying to add $ to
the end of the $RegStr... . But I can't get it to work!?

I'm sure this is easy for you guys that know what your doing!?
Thanks in advance, hope it makes sense!!!??
Russ


My System SpecsSystem Spec
Old 05-07-2009   #2 (permalink)
Rob Campbell


 
 

RE: $Variables into Regular expressions ?! help

I'm not positive I'm understanding the question exactly, but does this work?
Quote:

>$SearchStr ="$SuppliedStr1*$SuppliedStr2" + '$'
> $RegStr=[regex] $SearchStr
>
> $ArrayToSearch | where { $_ -match $RegStr }


"rush" wrote:
Quote:

> I've got a requirement to find a string in an array.
> Simple! but I need to search on the string contained in 2 variables,
>
> So basically I'm trying.
>
> $SearchStr ="$SuppliedStr1*$SuppliedStr2"
> $RegStr=[regex] $SearchStr
>
> $ArrayToSearch | where { $_ -match $RegStr }
>
> This appears to work OK, BUT I need to match where $SuppliedStr2 in
> the End of the line in the array, so I guess I'm trying to add $ to
> the end of the $RegStr... . But I can't get it to work!?
>
> I'm sure this is easy for you guys that know what your doing!?
> Thanks in advance, hope it makes sense!!!??
> Russ
>
>
My System SpecsSystem Spec
Old 05-07-2009   #3 (permalink)
RickB


 
 

Re: $Variables into Regular expressions ?! help

On May 7, 10:20*am, rush <russell.hanc...@xxxxxx> wrote:
Quote:

> I've got a requirement to find a string in an array.
> Simple! but I need to search on the string contained in 2 variables,
>
> So basically I'm trying.
>
> $SearchStr ="$SuppliedStr1*$SuppliedStr2"
> $RegStr=[regex] $SearchStr
>
> $ArrayToSearch | where { $_ -match $RegStr }
>
> This appears to work OK, BUT I need to match where $SuppliedStr2 in
> the End of the line in the array, so I guess I'm trying to add $ to
> the end of the $RegStr... . But I can't get it to work!?
>
> I'm sure this is easy for you guys that know what your doing!?
> Thanks in advance, hope it makes sense!!!??
> Russ
Looks like you want

$RegStr=[regex]"$SuppliedStr1*$SuppliedStr2`$"
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
regular expressions - why are they so hard to compose and decipher? PowerShell
regular expressions to replace but keep character? VB Script
New lines in regular expressions PowerShell
How to work with regular expressions PowerShell
Regular expressions PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46