Groups | Blog | Home
all groups > dotnet clr > october 2006 >

dotnet clr : Regex: trying to retrieve a specific value


Marco Shaw
10/23/2006 11:10:42 AM
I wasn't sure if .clr was the best .Net group to post to...

My original posting was in the powershell group. It seems the solution will
require some .Net magic, so I'm posting here.

In the original message below, I have a string, and am trying to match a
specific grouping of "<b>...</b>".

Somebody was kind enough to provide me with the following code for
Powershell:
[regex]::Matches((gc c:\test.txt), "<b>(.*?)</b>") |% { $_.Groups[1].Value }

This results in:
Forums user name:
Company name:
Country:
Personal quote:
Certification:
ITRC member since:
Last contribution date:
194
298
IT resource center forums
Total points:
349

I need a way to output only the last occurence. I assumed I could just run:
[regex]::Matches((gc c:\test.txt), "<b>(.*?)</b>") |% {
$_.Groups[1].Value[11] } <---Thinking "11" might match the last line

The above gives me pretty much nothing. It seems "Value[11]" is interpreted
as "give me the 11th character in *each* line".




----- Original Message -----
From: "Marco Shaw" <marco@Znbnet.nb.ca>
Newsgroups: microsoft.public.windows.powershell
Sent: Friday, October 20, 2006 4:02 PM
Subject: Grabbing a number after the Nth occurence of something within a
single string


[quoted text, click to view]

Ben Voigt
10/23/2006 4:17:56 PM

[quoted text, click to view]

Does powershell provide a "tail" command?

[quoted text, click to view]

AddThis Social Bookmark Button