![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
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 | Results from Regular Expression Match All, I have the following script in file parser.ps1. $a = get-content "C:\__Junk\ParseLuts\2008.05.01.log" foreach ($i in $a) { $regex = [regex] "(?<= AE).*(?= on Host)" $re = $regex.match($i) $re } Upon running this I get the following back when the match is true: Groups : { SMHMASTERA_SCU} Success : True Captures : { SMHMASTERA_SCU} Index : 14 Length : 15 Value : SMHMASTERA_SCU I only want to redirect the results for "Value" into a file. How can I just get the Value of "Value" and redirect into a file rather than everything from Groups to Length? Thanks from this newbie. Mike |
My System Specs![]() |
| | #2 (permalink) | ||||||||||||
| Guest | Re: Results from Regular Expression Match "Mike" <Mike@xxxxxx> wrote in message news:6179FCE3-31C3-4D91-87CF-E560F23FE7A2@xxxxxx
$re.Value >> <path to file> BTW you can also accomplish this a bit more succinctly by using switch like so: switch -regex -file C:\__Junk\ParseLuts\200805.01.log { '(?<= AE).*(?= on Host)' { $matches[1] >> <path to file> } } -- Keith | ||||||||||||
My System Specs![]() | |||||||||||||
| | #3 (permalink) |
| Guest | Re: Results from Regular Expression Match Here are a some more ideas: # some global variables $log = 'C:\__Junk\ParseLuts\2008.05.01.log' $regex = [regex]'(?<= AE).*(?= on Host)' $a = gc $log # 1 - original modified $values1 = $(foreach ($i in $a) { $re = $regex.match($i) if ($re.success) {$re.value} # avoid blanks }) # 2 - using Switch (Keith's has a bug) $values2 = $(switch -r -f $log {$regex {$matches[0]}}) # 3 - using Select-String $values3 = $(select-string $regex $log | % {$_.matches} | % {$_.value}) # 4 - using the Matches Method $values4 = $regex.matches(($a | out-string)) | % {$_.value} # write to file sc .\out.txt $values4 gc .\out.txt -- Kiron |
My System Specs![]() |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| regular expression help | Stimp | VB Script | 9 | 08-02-2008 06:05 PM |
| Simple Regular Expression | BJ | PowerShell | 6 | 01-30-2008 02:46 PM |
| Re: regular expression howto | Keith Hill [MVP] | PowerShell | 0 | 01-08-2008 09:45 PM |
| Extracting regular expression match from file | Brian Vallelunga | PowerShell | 2 | 06-18-2007 02:41 AM |
| simple regular expression | Ben | PowerShell | 2 | 02-19-2007 08:28 AM |