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

cscript vbscript regular expression - need help - request #2

Status
Not open for further replies.

cisco777

Programmer
Jul 22, 2005
13
US
May I ask to show how my below code should actually look in order for it to work correctly?

Since I am just starting to learn both cscript and regular expressions, I obviously do not yet have a grip on this.

I do not know if I need a read statement or what I am doing wrong.

Existing Code Follows:

'Create File System Objects
Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")

'Set objtxt = objFSO.OpenTextFile("c:\fileSuces, ForReading")

Set objtxt = objFSO.OpenTextFile("c:\fileError, ForReading")

Set StdOut = WScript.StdOut

' Set up the string that will be searched for the existence of a sub-string
' Pattern specifies the Regular Expression that is to be searched for
' False = Only match the first occurence of the pattern

StringToSearch = "Ended with errors "
' StringToSearch = "Ended with success "

StdOut.WriteLine "Contents of StringToSearch = " & StringToSearch
Set RegularExpressionObject = New RegExp
With RegularExpressionObject
' .Pattern = "with errors"
.Pattern = "with success"
.IgnoreCase = True
.Global = False
End With

expressionmatch = RegularExpressionObject.Test(StringToSearch)

If expressionmatch Then
StdOut.WriteLine "RegularExpressionObject.Pattern match was found in " & StringToSearch
Else
StdOut.WriteLine "RegularExpressionObject.Pattern match was Not found in " & StringToSearch
End If

objTxt.close

Set objFSO = Nothing
Set objTextFile = Nothing
set objStdOut = Nothing
Set RegularExpressionObject = Nothing

thank you.

steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top