Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is there any way I can extract an email address.....??? 1

Status
Not open for further replies.

JoJoH

Programmer
Joined
Jan 29, 2003
Messages
356
Location
US
Hi all,

Is there any way I can extract an email address from a page?

The basic concept is:

Here is a page with lots text

I want to extract an email address between the <a href=&quot;mailto:whoever@whoever.com&quot;>whoever@whoever.com</a>

But that email cannot be my email address (<> myemail@myemail.com)

Can someone please help me fit this puzzle together?

Thanks in advance!


JoJoH

 
Try this:
'put the email into variable
strEmail = &quot;<a href='mailto:ralphtrentacosta@comcast.net'>&quot;

'counts the number of charaters until it finds the :
intCol = InStr(strEmail,&quot;:&quot;)+1

'new variable holds all data past the :
strEmailExt = mid(strEmail, intCol)

'another variable extracts the just email address (if you do not include a &quot; or ' around the email address then change the 2 to a 1
strEmailExt2 = (left(strEmailExt, len(strEmailExt)-2))

'print out the email address
if strEmailExt2 <> &quot;myemail@myemail.com&quot; then
response.write strEmailExt2
end if

Let me know how this works out for you.
 
Here is version two this will work better:

strEmail = &quot;<a href='mailto:annietrentacosta@comcast.net' target='_blank'>&quot;
intCol = InStr(strEmail,&quot;:&quot;)+1
strEmailExt = Mid(strEmail, intCol)
intDot = InStr(strEmailExt,&quot;.&quot;)+3
strEmailExt2 = mid(strEmailExt,1,intDot)
if strEmailExt2 <> &quot;myEmail@myEmail.com&quot; then
response.write strEmailExt2
end if

the first one I posted will not work if you have anything past the email address, this one will. Not the target after the email address. it only extracts the email address.
 
one more:
This will handle the email address if you have a dot in the email address other then the expect dot at the end!
strEmail = &quot;<a href='mailto:bobbobb@yahoo.com'>&quot;
intCol = InStr(strEmail,&quot;:&quot;)+1
strEmailExt = Mid(strEmail, intCol)
intAt = InStr(strEmailExt,&quot;@&quot;)
intDot = InStr(strEmailExt,&quot;.&quot;)
If intDot < intAt Then
intDot = InStr(intAt, strEmailExt, &quot;.&quot;)
End If
WScript.Echo mid(strEmailExt,1,intDot+3)
 
Sorry last one, if you are going to read the data from a file, then use this code:

Dim ofso, openFile
Set ofso = CreateObject(&quot;Scripting.FileSystemObject&quot;)
set openFile = ofso.OpenTextFile(&quot;m:\programming\wsh\email\extractEmail.txt&quot;)

Do Until openFile.AtEndOfStream
strEmail = openFile.Readline
intCol = InStr(strEmail,&quot;:&quot;)+1
strEmailExt = Mid(strEmail, intCol)
intAt = InStr(strEmailExt,&quot;@&quot;)
intDot = InStr(strEmailExt,&quot;.&quot;)
If intDot < intAt Then
intDot = InStr(intAt, strEmailExt, &quot;.&quot;)
End If
strEmailOnly = mid(strEmailExt,1,intDot+3)
If (InStr(strEmailOnly,&quot;@&quot;) > 0) And (InStr(strEmailOnly,&quot;.&quot;) > 0) Then
wscript.echo strEmailOnly
End if
Loop
 
Wow Ralph! Thanks for your replies! I am impressed! I've ask this question a while back but has not gotten a satisfactory answer but now I did! Thanks! And sorry for the delay in replying! [smile]

JoJoH

 
<%
sourcestring=&quot;<a href='mailto:whoever@whoever.com'>whoever@whoever.com</a>&quot;

Set regEx = New RegExp
regEx.Global = True
regEx.IgnoreCase = True

regex.pattern = &quot;[^mailto:].*.([a-zA-Z]{2,5})&quot;

set matches = regEx.Execute(sourcestring)
for each match in matches
if match.value<>&quot;me@mysite.com&quot; then Response.Write match.value
next
%>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top