Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Retrieving entire line from text file using RegExp

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,63827
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Retrieving entire line from text file using RegExp
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 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,"")
 
 
Post #: 1
 
 RE: Retrieving entire line from text file using RegExp - 8/27/2008 3:01:26 AM   
  dm_4ever


Posts: 2669
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
Do you have a couple of sample lines?

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to CygnusX1)
 
 
Post #: 2
 
 RE: Retrieving entire line from text file using RegExp - 8/27/2008 3:22:09 AM   
  CygnusX1

 

Posts: 20
Score: 0
Joined: 8/16/2005
Status: offline
Here are some lines contained in the file:
=============================================================================
REQ_APPNAME = Microsoft WSE 2.0 SP3 Runtime
REQ_APP_VER = 2.0.5050.0
REQ_APPNAME1 = Adobe Acrobat Standard
REQ_APP_VER1 = 7.0.0
REQ_APPNAME2 = Sybase Client
REQ_APP_VER2 = 12.0
REQ_APPNAME3 =
REQ_APP_VER3 =

And....
; Product Version:  1.0
; Release:   1
; Build:   001
; Application ID:  7960
=============================================================================

Please keep in mind that sometimes the data between the property and the information contains spaces and/or tabs

(in reply to dm_4ever)
 
 
Post #: 3
 
 RE: Retrieving entire line from text file using RegExp - 8/27/2008 3:33:11 AM   
  dm_4ever


Posts: 2669
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
So you want to pull off 1.0, 1, 001, 7960 ?

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to CygnusX1)
 
 
Post #: 4
 
 RE: Retrieving entire line from text file using RegExp - 8/27/2008 3:36:25 AM   
  CygnusX1

 

Posts: 20
Score: 0
Joined: 8/16/2005
Status: offline
yes.  I can do it with a combination of RegExp, InStr, and Trim but I was wondering if RegExp could hadle most if not all of the duties.

(in reply to dm_4ever)
 
 
Post #: 5
 
 RE: Retrieving entire line from text file using RegExp - 8/27/2008 4:20:50 AM   
  dm_4ever


Posts: 2669
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
I'd cheat a little...


      

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to CygnusX1)
 
 
Post #: 6
 
 RE: Retrieving entire line from text file using RegExp - 8/27/2008 4:28:38 AM   
  dm_4ever


Posts: 2669
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
...not sure if this is the optimal way....but


      

< Message edited by dm_4ever -- 8/27/2008 4:31:19 AM >


_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to dm_4ever)
 
 
Post #: 7
 
 RE: Retrieving entire line from text file using RegExp - 8/27/2008 5:08:09 AM   
  CygnusX1

 

Posts: 20
Score: 0
Joined: 8/16/2005
Status: offline
Thanks!  So the SubMatches is the data that I need and all of the carrriage returns are removed before the regexp.execute.

Thanks again!

(in reply to dm_4ever)
 
 
Post #: 8
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Retrieving entire line from text file using RegExp Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts