Bob Hansen wrote:You need to use VBScript's Regular Expressions (RegEx) to extract the email address.
VBScript has RegEx tools. No time for sample now, but search tis forum for RegEx examples.
----------------------------
If not RegEx, you can also use Position and MidStr functions.
Thanks Bob
I found an example at
http://www.mjtnet.com/forum/viewtopic.php?p=16467#16467
I keep getting this error:
"Microsoft VBScript runtime error :5
Invalid procedure call or argument: 'Mid'
line 12, Column 2 "
I followed all the instructions posted in that thread but to avail. There was never really a solution for the VB script error.
Here is my code. I have
http://www.google.com on line 5 in the MSG1.txt to test the URL search script.
Code: Select all
//A VBScript Function to search a string for a regex pattern
//returns a list of matches separated by semicolons
VBSTART
Function regExSearch(patrn,str)
Set regEx = New RegExp ' Create regular expression.
regEx.Pattern = patrn ' Set pattern.
regEx.IgnoreCase = True ' Make case insensitive. Default=False
Set matches = RegEx.Execute(str)
List = ""
For each match in matches
List = List & match.value & ";"
Next
regExSearch = Mid(List,1,Len(List)-1)
End Function
VBEND
//Read the file contents into a variable
ReadFile>C:\RetrievedMail\MSG1.txt,FileData
//replace CRLF chars with VBScript equivalents
StringReplace>FileData,CR," & vbCR & ",FileData
StringReplace>FileData,LF," & vbLF & ",FileData
//Double quote any quotes for VBScript
StringReplace>FileData,","",FileData
//Perform the regex search
VBEval>regExSearch("REGEX_PATTERN","%FileData%"),URLList
//We now have a semicolon delimited list of URLs. We could explode this into an array:
Separate>URLList,;,URLS
If>URLS_COUNT>0
Let>k=1
Repeat>k
Let>ThisURL=URLS_%k%
MessageModal>ThisURL
//we could write it to a file:
WriteLn>C:\RetrievedMail\result.txt,result,ThisURL
Let>k=k+1
Until>k,URLS_COUNT
Endif
I also would like to know how I can replace
VBEval>regExSearch("REGEX_PATTERN","%FileData%"),URLList with this code
^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,6}$ to search for email addresses instead of URL's in the text file?
Thanks