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
> I'm trying to retrieve a single value from a HTML document.
>
> Here's where I'm at so far. I've searched the file for the string "Total
> points" below.
>
> There's a string "349" after embedded by "<b>" and "</b>". There are a
> few
> occurences of "<b>" and "</b>" though.
>
> How can I grab the number between the Nth occurece of "<b>" and "</b>"?
> That might be the best place to start...
>
> PS C:\> (get-content "c:\file.txt") -like "*Total points:*"
> <td valign="top"><table border="0" cellspacing="0" cellpadding="0"
> width="260" align="center"><tr><td colspan="
> 3"><b>IT resource center forums</b></td></tr><tr><td width="190"><b>Total
> points:</b></td><td align="center" width="30"
> valign="bottom"> <img
> src="/service/forums/images/expressions/cap.gif"
> alt="This member has accumulated 250 or mo
> re points"></td><td width="30" align="right"> <b>349</b></td><td
> width="10"
> align="right"> </td></tr></table><tabl
> e border="0" width="260" cellspacing="0" cellpadding="0" align="center"
> ><tr><td colspan="2" width="220"><span class="c
> olor003366">»</span> <a
> href="/service/forums/familyhome.do?familyId=295">Your questions regarding
> ITRC Foru
> ms</a></td><td width="30" align="right">10</td><td
> width="10"> </td></tr><tr><td width="30" align="center" valign=
> "top"><span class="color003366">»</span></td><td width="190"
> valign="top"><a href="/service/forums/categoryhome.d
> o?categoryId=296">general</a></td><td width="30" valign="top"
> align="right">10</td><td width="10" align="right"> <
> /td></tr></table><table border="0" width="260" cellspacing="0"
> cellpadding="0" align="center" ><tr><td colspan="2" widt
> h="220"><span class="color003366">»</span> <a
> href="/service/forums/familyhome.do?familyId=121">Management s
> oftware and system tools</a></td><td width="30" align="right">339</td><td
> width="10"> </td></tr><tr><td width="30"
> align="center" valign="top"><span
> class="color003366">»</span></td><td width="190" valign="top"><a
> href="/servic
> e/forums/categoryhome.do?categoryId=162">OV Operations (ITO)</a></td><td
> width="30" valign="top" align="right">339</td>
> <td width="10" align="right"> </td></tr></table><br><br></td></tr>
Ben Voigt - 23 Oct 2006 22:17 GMT
>I wasn't sure if .clr was the best .Net group to post to...
>
[quoted text clipped - 27 lines]
> [regex]::Matches((gc c:\test.txt), "<b>(.*?)</b>") |% {
> $_.Groups[1].Value[11] } <---Thinking "11" might match the last line
Does powershell provide a "tail" command?
> The above gives me pretty much nothing. It seems "Value[11]" is
> interpreted as "give me the 11th character in *each* line".
[quoted text clipped - 53 lines]
>> width="30" valign="top" align="right">339</td>
>> <td width="10" align="right"> </td></tr></table><br><br></td></tr>