0
2
I have a text file named file.txt
which contains,
myname1234@gmail.com:
myname1234@gmail.com:password000
secondmail@hotmail.com:
secondmail@hotmail.com:qwerty123
philip007@ymail.com:
philip007@ymail.com:iloveyou
I am running a vbs program,
Const SCRIPT_NAME = "Extract E-mail Addresses"
Dim objFSO, objFil, arrAdr, varBuf, varInp, varOtp
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFil = objFSO.OpenTextFile("file.txt")
varBuf = objFil.ReadAll
objFil.Close
arrAdr = Split(FindString(varBuf, "\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b"), ",")
Set objFil = objFSO.CreateTextFile("results.txt")
For Each varBuf In arrAdr
objFil.WriteLine varBuf
Next
objFil.Close
Set objFil = Nothing
Set objFSO = Nothing
MsgBox "Extraction complete.", vbInformation + vbOKOnly, SCRIPT_NAME
WScript.Quit
Function FindString(strText, strFind)
Dim objRegEx, colMatches, objMatch
Set objRegEx = CreateObject("VBscript.RegExp")
With objRegEx
.IgnoreCase = True
.Global = True
.Pattern = strFind
Set colMatches = .Execute(strText)
End With
For Each objMatch In colMatches
FindString = FindString & objMatch.Value & ","
Next
If Len(FindString) > 0 Then
FindString = Left(FindString, Len(FindString) - 1)
End If
Set objRegEx = Nothing
Set colMatches = Nothing
Set objMatch = Nothing
End Function
Expected output,
myname1234@gmail.com:password000
secondmail@hotmail.com:qwerty123
philip007@ymail.com:iloveyou
But, Actual result,
myname1234@gmail.com
myname1234@gmail.com
secondmail@hotmail.com
secondmail@hotmail.com
philip007@ymail.com
philip007@ymail.com
My need : I like to filter only email:password from the file.txt
text file. But, using above vbs i can only able to filter email address. Please fix my code to get my expected output. Thanks a lot in advance.
Note : The email and password may vary with different text files. Also am noob to vbs. Being frank i got the above code from Quora. Kindly help me. Even same solution using batch program is also fine for me. Waiting for valuble solutions :)
This works, Give Expected output. But, Gives this error - https://i.postimg.cc/dQpwG5d7/Capture.png
– Philip – 2019-11-12T10:01:43.103@Philip It is because the input file format does not match the one shown. Code updated. – Akina – 2019-11-12T10:03:12.573
Perfect now without error. :) Thanks a lot bro. U made my work easier. – Philip – 2019-11-12T10:07:40.173