Hi all,
I'm trying to search a text file for 2 values using regex and format the output so that the values are side by side in a tab delimited format
Text file looks like this. 'Val' is constant, but the number after Val will be different
----------------------------
Value Val 1
.
.
more text here
.
.
Phone: 124566
.
.
Value Val 2
.
.
Phone: 345672
----------------------------
So the output should look something like (no headings required), only the raw data with a tab or space in between
Val 1 124566
Val 2 345672
I can find the first value, but don't know how to add the second value and format it. Can someone please help?
So far, the code looks like this:
Current output looks like:
Val 1
Val 2
Val 3
etc
I'm trying to search a text file for 2 values using regex and format the output so that the values are side by side in a tab delimited format
Text file looks like this. 'Val' is constant, but the number after Val will be different
----------------------------
Value Val 1
.
.
more text here
.
.
Phone: 124566
.
.
Value Val 2
.
.
Phone: 345672
----------------------------
So the output should look something like (no headings required), only the raw data with a tab or space in between
Val 1 124566
Val 2 345672
I can find the first value, but don't know how to add the second value and format it. Can someone please help?
So far, the code looks like this:
Code:
Const ForReading = 1
Set objRegEx = CreateObject("VBScript.RegExp")
objRegEx.Global = True
objRegEx.Pattern = "Val\s+\d+"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\data.txt", ForReading)
strSearchString = objFile.ReadAll
objFile.Close
Set colMatches = objRegEx.Execute(strSearchString)
If colMatches.Count > 0 Then
strMessage = "The following values were found:" & vbCrlf
For Each strMatch in colMatches
strMessage = strMessage & strMatch.Value & vbcrlf
Next
End If
Wscript.Echo strMessage
Val 1
Val 2
Val 3
etc