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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

fso and reg expression help needed 2

Status
Not open for further replies.

ktucci

Programmer
Apr 23, 2001
146
US
i am a little new at using fso and reg expressions,

i am trying to open a file(see example below) using FSO and use reg expressions to parse out the first line 'No such host is known. <xtestx.com>' which can vary in content or not even exist, then i need to parse out the value 'keith@xtestx.com' after 'X-TrackerEmail:' , then i need to parse out the value '7FDBED87791505439D3E0EB423103B7F' after 'X-Tracker:'...these values will vary from file to file...after parsing the values from the example below:

No such host is known. <xtestx.com>
keith@xtestx.com
7FDBED87791505439D3E0EB423103B7F

i would like to have each parsed value be its own string for further processing

see file contents below for example:


----------------file start-------------------------------------
No such host is known. <xtestx.com>

x-receiver: <keith@xtestx.com>
x-sender: <keith@test.com>
Message-ID: <2471732-22002422234427640@xtestx.com>
X-EM-Version: 6, 0, 1, 0
X-EM-Registration: #00606305108119002B30
X-TrackerEmail: keith@xtestx.com
X-Tracker: 7FDBED87791505439D3E0EB423103B7F
From: &quot;test&quot; <keith@xtestx.com>
To: keith@xtestx.com
Subject: Dear K T ***TESTING1*
Date: Tue, 2 Apr 2002 18:44:27 -0500
MIME-Version: 1.0
Content-Type: multipart/alternative;
---------------file end------------------------------------

thanks for any help

it will be greatly appreciated

keith
 
the using of reg expressions is not a requirement, so any ideas using reg expressions or other methods are equally useable for this particular question
 
I might the following:


dim HostName as String
dim TrackEmail as String
dim TrackKey as String

HostName = &quot;&quot;
TrackEmail = &quot;&quot;
TrackKey = &quot;&quot;
FileHandle = FreeFile
Open <YourTextFile> for input as #FileHandle
While EOF(FileHandle) = False
Line Input #FileHandle, DataLine
if (left(DataLine, 22) = &quot;No such host is known.&quot;) then
HostName = Mid(Dataline, 23)
else
if (left(dataline, 15) = &quot;X-TrackerEmail:&quot;) then
TrackEmail = Mid(DataLine, 16)
else
if (left(dataline, 10) = &quot;X-Tracker:&quot;) then
TrackKey = Mid(DataLine, 11)
endif
endif
endif
Wend
Close #FileHandle

Good Luck
 
Seeing as I led you into this I think it's incumbent upon me to get you out of it. If you copy the text to a file called email.txt, then copy this code into the Form_load procedure of a form, then set a reference to the Microsoft VBScript Regular Expressions 5.5 and Microsoft Scripting Runtime then you'll see how it works. the part in parentheses in the Pattern property captures the pattern as a SubMatch.

Private Sub Form_Load()
Dim fso As New FileSystemObject
Dim ts As TextStream
Dim sFileText As String
Dim sPattern As String
Dim objMatcher As New RegExp
Dim objMatches As MatchCollection
Set ts = fso_OpenTextFile(&quot;C:\email.txt&quot;)
sFileText = ts.ReadAll

With objMatcher
.MultiLine = True
.IgnoreCase = True
'extract the first line
.Pattern = &quot;^.*\n&quot;
Set objMatches = .Execute(sFileText)
MsgBox objMatches(0)
'extract the second line
.Pattern = &quot;X-TrackerEmail: (.*)&quot;
Set objMatches = .Execute(sFileText)
MsgBox objMatches(0).SubMatches(0)
'extract the second line
.Pattern = &quot;X-Tracker: (\w+)&quot;
Set objMatches = .Execute(sFileText)
MsgBox objMatches(0).SubMatches(0)
End With
End Sub
 
thanks to CajunCenturion & muesli, both solutions worked great...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top