Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regular Expression Search Pattern 2

Status
Not open for further replies.

helpeachother

Programmer
Joined
Jun 1, 2005
Messages
13
Location
CA
Hi, Everyone:

Thank you so much for your help with my debug question posted yesterday. I am sorry that I need your help again.

The following is a function a wrote in VB.NET to use the regular expression 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

 
James:

How can I send you attachment? I need to show you the block of the text the pattern is searching for the matches. It is a screen capture.

Here is the table I copied from our intranet, but you cannot see the tags.

Date DS
Used
(KB) DS
Available
(KB) DS
Total
(KB) PS
Used
(KB) PS
Available
(KB) PS
Total
(KB) DS/PS
Total
(KB) Spare
(KB) Provision
Total
(KB)
20050508 00:00:00 1046270 43137 1089407 88173 10130 98303 1187710 196608 1384318
20050509 00:00:00 1046774 42633 1089407 88173 10130 98303 1187710 196608 1384318
20050510 00:00:00 1046762 42645 1089407 88173 10130 98303 1187710 196608 1384318
20050511 00:00:00 1046966 42441 1089407 88173 10130 98303 1187710 196608 1384318
20050512 00:00:00 1046865 42542 1089407 88173 10130 98303 1187710 196608 1384318
20050513 00:00:00 1046681 42726 1089407 88173 10130 98303 1187710 196608 1384318
20050514 00:00:00 1046596 42811 1089407 88173 10130 98303 1187710 196608 1384318
20050515 00:00:00 1046857 42550 1089407 88173 10130 98303 1187710 196608 1384318
20050516 00:00:00 1046799 42608 1089407 88173 10130 98303 1187710 196608 1384318
20050517 00:00:00 1046834 42573 1089407 88173 10130 98303 1187710 196608 1384318
20050518 00:00:00 1046656 42751 1089407 88173 10130 98303 1187710 196608 1384318
20050519 00:00:00 1046617 42790 1089407 88173 10130 98303 1187710 196608 1384318
20050520 00:00:00 1064342 57833 1122175 88173 10130 98303 1220478 163840 1384318
20050521 00:00:00 1064361 57814 1122175 88173 10130 98303 1220478 163840 1384318
20050522 00:00:00 1064399 57776 1122175 88173 10130 98303 1220478 163840 1384318
20050523 00:00:00 1064549 57626 1122175 88173 10130 98303 1220478 163840 1384318
20050524 00:00:00 1064973 57203 1122176 88173 10130 98303 1220479 163840 1384319
20050525 00:00:00 1064922 57253 1122175 88173 10130 98303 1220478 163840 1384318
20050526 00:00:00 1065085 57090 1122175 88173 10130 98303 1220478 163840 1384318
20050527 00:00:00 1064855 57321 1122176 88173 10130 98303 1220479 163840 1384319
20050530 00:00:00 1065069 57106 1122175 88173 10130 98303 1220478 163840 1384318
20050531 00:00:00 1065147 57028 1122175 88173 10130 98303 1220478 163840 1384318
20050601 00:00:00 1064855 57320 1122175 88173 10130 98303 1220478 163840 1384318
20050602 00:00:00 1064959 57216 1122175 88173 10130 98303 1220478 163840 1384318
20050603 00:00:00 1065264 56911 1122175 88173 10130 98303 1220478 163840 1384318
20050604 00:00:00 1064944 57231 1122175 88173 10130 98303 1220478 163840 1384318
20050605 00:00:00 1064850 57325 1122175 88173 10130 98303 1220478 163840 1384318



Thanks:-)

KWright
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top