Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / CLR / October 2006

Tip: Looking for answers? Try searching our database.

Regex: trying to retrieve a specific value

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Marco Shaw - 23 Oct 2006 15:10 GMT
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">&nbsp;<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">&nbsp;</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">&raquo;</span>&nbsp;<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">&nbsp;</td></tr><tr><td width="30" align="center" valign=
> "top"><span class="color003366">&raquo;</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">&nbsp;<
> /td></tr></table><table border="0" width="260" cellspacing="0"
> cellpadding="0" align="center" ><tr><td colspan="2" widt
> h="220"><span class="color003366">&raquo;</span>&nbsp;<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">&nbsp;</td></tr><tr><td width="30"
> align="center" valign="top"><span
> class="color003366">&raquo;</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">&nbsp;</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">&nbsp;</td></tr></table><br><br></td></tr>

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.