I am trying to learn regular expression in vbscript. the below is the code. when I run the code i receive the same match message no matter if i use the input file that ended successfully or the input file that ended with errors.
do i need to add a read statement or am i missing more?
'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
do i need to add a read statement or am i missing more?
'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