Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Sep 2002
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Recognise email id and links

    hi,

    If the paragraph coming from the database looks like the following:

    Mails can be sent to the following address mail@abc.com. Visit the site for the latest news at www.xyz.com.
    For the best information on what’s going on around visit http://www.xyz.com. For enquires mail at enquiry@xyz.com and so on..

    How is it possible to recognize all the email address and links from the above and display them as – mailId@abc.com (<a href = mailto:mailId@abc>mailid@abc.com</a>) and links as http://www.xyz.com.

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Cincinnati, OH
    Posts
    545
    Thanks
    0
    Thanked 0 Times in 0 Posts
    My first guess would be to do a InStr(@) to find the emails "@" or urls "http://". When you find a "@" in your paragraph you will have to do some more string manipulation. For emails you will have to use InStrRev("your paragraph"," ",InStr("@")) and find a " " for the beginning of your email. You then can do a InStr(InStr(@),"paragraph"," "). These will return numeric postions of the email address with these values do a Mid() to return this section (or email address). Finally do a Replace(). You may want to check to make sure it is somewhat of a valid email before you set the link too. This is based that there can not be " " in a email address. These same functions can be used to detect a url. One more note is that InStr() or InStrRev() finds the first occurence of the string you are searching for. What this means is that when you are searching for a "@" be sure to set the start postion of the last @ found.

    I hope this helps and not confuse.

    vbscript functions

  • #3
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    what allida77 said + check for a dot (".") and chack if the possition of the dot is higher then the position of the @

    of coarse. this isn't bulletproof.

    if i relly need to be sure. I just ask them to fill in an email adress and then mail something to then (pasword, registration key, ...) and require them to get back to my site an type in the key or stuff

    but even then ....

    the email-account can be closed down the next day etc etc.

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    In order to do this right, you need to parse all of the links out using regular expression matches.

    Usually Allida77 and raf are absolutely correct when they post solutions - but in this case, using typical string manipulation is taking the wrong path, and won't accomplish what you're trying to do at all, unless you want to use dozens of lines of code where perhaps one line would be appropriate. (No offense intended to raf or Allida77... regular expressions are not as well known as they should be!).

    Are you familiar with regex's? It looks like your example will require a few precise ones, so you might want to look up regular expression examples for parsing links on http://www.google.com, etc., although I can help you out with them somewhat, perhaps, as we have some good regex's at work (some of which I helped devise) for at least <a href=""> type links, and www.whatever.com type links, etc.

    You might also want to do a search of the forums, since many _very_ good regular expressions have been posted that do exactly this type of pattern matching.

    Once you figure regular expressions out, they are much more precise than any other string manipulation technique. Using InStr() is just ghastly in this case...
    Last edited by whammy; 03-01-2003 at 03:10 AM.
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #5
    New Coder
    Join Date
    Sep 2002
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks to all of you for replying.
    I am not familiar with regex's. I would appreciate if you could help me. I need to recognise mail ids and urls.
    As suggested by you i will search for regular expression examples for parsing links.

  • #6
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok whammy i stand corrected. Maybe i'll start a self-help group

    i'll look into regex's. (Maybe, that is, since they only say the email or url is "well formed" and not that they actually exist. I alway try to avoid using email communication in my app's and they are never vital + if a user inserts a non-existing email, this should only have negative effects for him)

    For external url's: the same + add a disclaimer or a message box that say you're now leaving the app's site and that you can't secure that the link points to an existing page etc etc

  • #7
    Regular Coder
    Join Date
    Jun 2002
    Location
    Cincinnati, OH
    Posts
    545
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I will have to join Raf's self help group. I actually like doing string manipulations so since I dont know regexs my first instinct is to always use all the string manipulation functions. I actually tried to do this at home to see how many lines I could do it in. In a perfect world where users type in emails and http://s properly it is really not a problem but since that world doesnt exist the code gets kind of flaky. Regexs have always been on the list of things to learn but I just have never done it.

  • #8
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    http://www.regexlib.com/

    That link will give you quite a few to play around with...

    Some good resources:

    http://www.4guysfromrolla.com/webtech/090199-1.shtml

    http://www.4guysfromrolla.com/webtech/042501-1.shtml


    Although these are in javascript, all of these sames things can be used in almost any programming language:

    http://devedge.netscape.com/library/...de/regexp.html

    http://www.siteexperts.com/tips/func...ts23/page1.asp

    Believe me, they are REALLY useful... I have some you can look at here that are mostly pretty simple:

    http://www.solidscripts.com/downloads/functions.txt
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •