This code opens a txt file, runs the regex against it.. then saves the output as a different file...
Code:
Sub RegEx()
Dim oFS As FileSystemObject
Dim oText As TextStream
Dim strRawData, strFormattedData As String
Dim oRegEx As RegExp
Dim oMatches As MatchCollection
Dim oMatch As Match
Set oRegEx = New RegExp
oRegEx.Global = True
oRegEx.Pattern = "\s[A-Z0-9\s]*\s*\d{7,12}\s*[^(]\d\d:\d\d[^)]\s*\d*/\d*/\d*\s"
' Other ID \s[A-Z0-9]\s*
' Invoice # \d{10,}\s*
' Time [^(]\d\d:\d\d[^)]
' Date \s\d*/\d*/\d*\s
Set oFS = New FileSystemObject
Set oText = oFS.OpenTextFile("Sourcefile.txt", ForReading)
strRawData = oText.ReadAll
oText.Close
Set oText = Nothing
Set oMatches = oRegEx.Execute(strRawData)
Set oText = oFS.OpenTextFile("outputfile" & Format(Date, "mm-dd-yyyy") & ".txt", ForWriting, True)
For Each oMatch In oMatches
strFormattedData = Replace(oMatch, vbCr, "")
oText.WriteLine Replace(strFormattedData, vbLf, "")
Next oMatch
oText.Close
Set oText = Nothing
Set oRegEx = Nothing
Set oMatches = Nothing
Set oFS = Nothing
MsgBox "New Parsed File Created"
End Sub