tags:

views:

35

answers:

2

Trying to parse a text file for records starting with an RH space and a date. I need to return the entire line. I expect to find about 6000 in the file. Any help would be greatly appreciated.

Example of a full record:

RH 09/27/08 11:49 11:49:00.224 COA292 H393 2664FB753 178 -54.82 8.98 C 431 264 13 040 34 24.45-074 58 57.93 H

Snipit of text file:

Œ RH 09/27/08 11:49 11:49:00.292 JBU521 L536 1555FA320 089 -24.47 6.32 8 275 219 13 040 38 56.79-074 19 16.83 Œ RH 09/27/08 11:49 11:49:00.280 BTA2094L063 4142FE145 044 -35.94 8.82 P 257 135 3 040 38 42.65-074 34 44.99 Œ RH 09/27/08 11:49 11:49:00.372 1374479 479 1374FUNK 360 -44.41 16.89 # 385 241 040 44 33.76-074 48 06.66 Œ RH 09/27/08 11:49 11:49:00.456 1274230 230 1274FUNK -01 -46.61 24.18 # 13 031 040 51 07.41-074 53 12.90 Œ RH 09/27/08 11:49 11:49:00.540 EJA691 S083 3354FC56X 108 -26.95 18.12 C 293 283 13 040 49 51.03-074 26 04.43 Œ RH 09/27/08 11:49 11:49:00.576 COA768 H592 1560FB753 029 -16.03 11.96 4 242 322 13 040 46 22.69-074 10 09.52 H Œ RH 09/27/08 11:49 11:49:00.620 N3663B S211 3472FBE10 020 -22.72 19.23 5 161 228 10 040 51 54.68-074 20 58.46 Œ RH 09/27/08 11:49 11:49:00.684 N45002 S522 3525FPA31 030 -21.66 21.79 A 161 165 8 040 54 38.81-074 20 23.63 Œ RH 09/27/08 11:49 11:49:00.776 BTA2296L418 2615FE145 104 -21.82 28.5 C 323 357 13 041 01 08.25-074 22 39.48 Œ RH 09/27/08 11:49 11:49:00.832 CJC3304L450 2256FDH8D 070 -25.09 38.17 P 242 208 3 041 09 46.94-074 29 51.57 Œ RH 09/27/08 11:49 11:49:00.836 N721AF S517 1553FPC12 111 -15.1 23.29 4 198 273 13 040 57 37.15-074 12 24.13 Œ RH

Thanks!

+2  A: 
^.*RH \d\d/\d\d\/\d\d.*$

will match a line that contains RH, space, and three double-digit groups separated by slashes.

In VB.NET, in order to iterate over all matches in a string:

Dim RegexObj As New Regex("^.*RH \d\d/\d\d/\d\d.*$", RegexOptions.Multiline)
Dim MatchResults As Match = RegexObj.Match(SubjectString)
While MatchResults.Success
    ' matched text: MatchResults.Value
    ' match start: MatchResults.Index
    ' match length: MatchResults.Length
    MatchResults = MatchResults.NextMatch()
End While
Tim Pietzcker
I code in Vb.NET Thanks
Tried to implement this, but it does not return any values. Could be the language thing you mentioned above.
+1  A: 

you posted one long string, so you can split on "RH" using the split function on "RH", then iterate the items , split on spaces and check the first element using IsDate() eg assume "strContents" is the one long string sample.

data=Split(strContents,"RH")
For i=LBound(data) To UBound(data)
  s = Split(data(i)," ")  
  If IsDate(s(1)) Then
    WScript.Echo "RH"&data(i)
  End If 
Next

IsDate() checks for valid date.

ghostdog74
Worked perfectly, tried doing this earlier strContents.split("RH") but it did not break the same as your method. Thanks!