Search text

E

Eric

I try to search pattern using RegExp method but it wont work. Data
contain emails which i save it into a textfile and want to read the
contents of email (Date, Customer Name, Street, Subject etc etc). Date,
Customer Name etc they all are in large braket and on the next line
their description is available. Needs help how to i read the word Date,
Customer Name etc and then fetch the next line record.

Dim fso, fil, ts, sContents
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set fil = fso.getfile(server.mappath("myemails.txt"))
Set ts = fil.openastextstream(1)
sContents = ts.readall
dim strPatternString as String
strPatternString = "\s\S"
sPattern = "Street\:\s*([" & strPatternString & "]+?)[\r\n]+"
Dim rx
Set rx = New RegExp
rx.Global = True
rx.IgnoreCase = True
rx.MultiLine = True
rx.Pattern = sPattern
Set mc = rx.Execute(sContents)
For Each rm In mc
sFrom = rm.SubMatches(0)
response.write("<br>")
response.write(sFrom)
Next
ts.close
Set rx = nothing
Set ts = nothing
Set fil = nothing
Set fso = nothing
---------------SAMPLE DATA---------------
[Date]
Wed Aug 02 10:29:18 EDT 2006
[Novell ID]
EZARDOYA
[Subject]
Research - 885031
[Customer's Name]
SIMONE LERINA
[Street]
44 ELIZABETH AVE APT BSMT
[City, State, Zip]
 
G

Guest

Here's an easier approach. Doesn't use RegularExpressions, but it works just
as well:

1) Create an instance of a System.IO.StreamReader, specifying the file
2) Create a loop that calls ReadLine

(ReadLine returns a string that represents the entire line of text. You can
chech the returned value to see if the line was "[Date]" "[Subject]" or
whatever...then call Readline again to get teh actual Data.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Read data from the email body 1
Pattern Matching 1
Insert Data 2
Logical Error 1

Top