Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

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.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Re: how to tokenize a string into a variable via regex

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 07-14-2008   #1 (permalink)
Kiron
Guest


 

Re: how to tokenize a string into a variable via regex

$string -replace '.+(.x..).+','$1'

# if you're extracting hex values
$string -replace '.+(0x\d{2}).+','$1'

--
Kiron

My System SpecsSystem Spec
Old 07-14-2008   #2 (permalink)
Kryten
Guest


 

Re: how to tokenize a string into a variable via regex

Hi,

[array]$a = "nfjknvwjkvnkw0x33jniids", "snsdacjqksl0x11m;kcv;",
"jnefvm;ekl;ewlv kl;0x99mkj;mkj"
$regex = [regex]"0x\d{2}"
$b = $a | % { $($regex.Match($_).value) }

So your variables will now be:

$b[0] = 0x33
$b[1] = 0x11
$b[2] = 0x99

This assumes that it will always be two digits after the 0x bit.

I can see a Tao Ma or kiron masterpiece coming on here...

Hope this helps,

Stuart





My System SpecsSystem Spec
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Find a string within a variable string Edward.A.Gonzalez PowerShell 4 08-15-2008 08:13 AM
SSIS - string variable! Daniel .NET General 0 05-15-2008 05:53 AM
Subject: using a Variable with/in a string DonP PowerShell 2 02-27-2008 02:11 PM
Finding a regex position in a string Jacob Saaby Nielsen PowerShell 7 11-26-2007 06:44 AM
Remove-item on a variable name using a regex Marco Shaw PowerShell 2 12-07-2006 01:13 AM


Update your Vista Drivers Update Your Drivers Now!!

Vistax64.com 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 2005-2008