Current location: Hot Scripts Forums » Programming Languages » Visual Basic » Regular Expression


Regular Expression

Reply
  #1 (permalink)  
Old 06-02-05, 07:40 PM
KHWright KHWright is offline
New Member
 
Join Date: Jun 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Regular Expression

Hi, Everyone:

I am a new member of this group and I need your help.

I wrote a function in VB.NET to use regular expressions to get a few numbers from a block of text I grabed from a table on our intranet. It supposes to grab the 1st, 4th, 8th and 9th number on the row of the table that matches the searchDate. (see the code below.)

However, when I test the code, it does not go through the " If num.Count > 1 Then" loop. It seems that the regExp of numPattern does not get a match, but it should. Can anyone help mw with this?

Thanks,

KHWright




Function getMemoryData(ByVal block As String, ByVal searchDate As String) As String()

Dim matches, num As System.Text.RegularExpressions.MatchCollection
Dim regExp As Regex
Dim datePattern, numPattern, temp, mData(3) As String

datePattern = "<td[^>]*>(\d\d\d\d)(\d\d)(\d\d) \d\d:\d\d:\d\d</td>"
numPattern = "<td align=middle>(\d+)\s*</td>\s*<td align=middle>\d+\s*</td>\s*<td align=middle>\d+\s*</td>" + _
"\s*<td align=middle>(\d+)\s*</td>\s*<td align=middle>\d+\s*</td>\s*<td align=middle>\d+\s+</td>" + _
"\s*<td align=middle>\d+\s*</td>\s*<td align=middle>(\d+)\s*</td>\s*<td align=middle>(\d+)\s*</td>"


mData(0) = "" : mData(1) = "" : mData(2) = "" : mData(3) = ""

regExp = New Regex(datePattern)
matches = regExp.Matches(block)
regExp = Nothing






'Only do this if there was a result from MTX Memory page

For Each m As Match In matches 'process matches
temp = m.Value

If InStr(1, temp, searchDate, CompareMethod.Text) > 0 Then


regExp = New Regex(numPattern) 'establish a regular expression
num = regExp.Matches(temp) 'get your matches

'Grab the last two numbers. these should be your Max & Avg
If num.Count > 1 Then
'DS = 1 PS = 4 : Spare = 7 : Provision = 8
mData(0) = num(num.Count - 3).Value
mData(1) = num(num.Count - 2).Value
mData(2) = num(num.Count - 1).Value
mData(3) = num(num.Count - 0).Value

End If

End If
Next

Return (mData)

End Function
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Regular Expression search pattern KHWright Perl 1 06-22-05 12:38 AM
HELP!!! - Invalid preceding regular expression CMIVXX PHP 1 01-04-05 04:55 AM
I want a crowler and abstraction from Regular Expression oiranoinu Script Requests 4 11-26-04 12:31 AM
Regular Expression IP Address Replacement CMIVXX PHP 3 11-20-04 08:27 AM
suggest a regular expression gmadhukarreddy Perl 2 01-08-04 01:56 AM


All times are GMT -5. The time now is 01:07 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.