Login | |
|
 |
Retrieving entire line from text file using RegExp - 8/27/2008 1:22:20 AM
|
|
 |
|
| |
CygnusX1
Posts: 20
Score: 0
Joined: 8/16/2005
Status: offline
|
What I am looking to do is to retrieve an entire line from a text file starting after the pattern to but not including the carriage return. I can return the entire line and use InStr, Replace, and Trim to capture the desired information but I was wondering if RegExp can do most of this for me. So I want to know if RegExp can be used to find a string and return that line from the end of that string to (but not including) the carriage return? The text file has various information that I need to return. Here is waht I have thus far that will return the entire line: Dim sSearchText,a,b,c Set fso = CreateObject("Scripting.FileSystemObject") Set re = CreateObject("vbscript.regexp") Set f = fso.GetFile("path\file.txt") Set oText = fso.OpenTextFile(f.Path,1) sSearchText = olText.ReadAll oText.Close With re .Global = True .Pattern = "(.{0,}application = .{0,}\n)(.{0,}name = .{0,}\n)(.{0,}version = .{0,}\n)" .IgnoreCase = True End With Set Matches = re.Execute(sSearchText) Set oMatch = Matches(0) a = Replace(Trim(Mid(oMatch.SubMatches(0),InStr(1,oMatch.SubMatches(0),Chr(61),1)+1)),vbcrlf,"") b = Replace(Trim(Mid(oMatch.SubMatches(1),InStr(1,oMatch.SubMatches(1),Chr(61),1)+1)),vbcrlf,"") c = Replace(Trim(Mid(oMatch.SubMatches(2),InStr(1,oMatch.SubMatches(2),Chr(61),1)+1)),vbcrlf,"")
|
|
| |
|
|
|
|
|