Author: Ariel G. Saputra

Ariel G. Saputra is a web developer from Bali, Indonesia. He skilled in CSS, XHTML, ASP, C#, PHP, jQuery and Flash Actionscript. Lately he dive into Rails world and really impressed.

Currently he is running his own business at www.chazzuka.com some of his portfolio could be found at developer.web.id

twitter, plurk, linkedin, facebook, flickr

Ariel G. Saputra has written 17 articles for us.

6 Comments For This Post

  1. roei

    22/06/09 20:05

    it’s not working

  2. SzR

    22/06/09 21:13

    autolinkfunction is not working.

  3. Ariel G. Saputra

    30/06/09 07:21

    @roei + SzR
    yeah sorry all the escape chars was stripped out in the pattern, it should be working now.
    thanks for reporting

  4. Bauke

    26/01/10 00:06

    Great!

    a) One of the first results of my query in Google
    a) Works like a charm!

    Thanks a lot

  5. jannerman

    16/03/10 19:59

    great bit of code, the only way it could be better was if it was able to interpret http://www.google.co.uk and pass it as http://www.google.co.uk rather than http://www.thehostwebsite.co.uk/www.google.co.uk but it’ll do for now!

  6. Pablo

    01/04/10 20:52

    Very cool…awesome use of Regex!

    Here’s a more complete function which isn’t as pretty, but will handle many more variations of links:

    ‘::Auto-Link Function
    Function AutoLink(str,target)

    ‘split into multiple ‘words’
    If IsNull(str) OR str = “” Then Exit Function
    str = Split(Trim(str))

    ‘loop through and process each ‘word’
    For wCnt = 0 To UBound(str)
    wStr = str(wCnt)

    ‘check for url wString
    If (Left(LCase(wStr),4) = “http” AND Len(wStr) > 11 AND InStr(wStr,”://”) > 0) _
    OR (Left(LCase(wStr),4) = “www.” AND Len(wStr) > 11 AND InStrRev(wStr,”.”) > 4) Then
    arrChar = “! 0 Then
    lwStr = Right(wStr,Len(wStr)-locChar+1)
    wStr = Left(wStr,locChar-1)
    Exit For
    End If
    Next
    If InStr(LCase(wStr),”http://”) = 0 Then pwStr = “http://”
    wStr = “” & wStr & “” & lwStr

    ‘check for email wString
    ElseIf (InStr(wStr,”@”) > 0 AND len(wStr) > 4 _
    AND InStr(wStr,”@”) = InStrRev(wStr,”@”) _
    AND InStr(wStr,”href=mailto:”) <= 0) Then
    wStr = "” & wStr & “
    End If

    ‘save newly formatted ‘word’
    str(wCnt) = wStr
    Next

    ‘combine and return completely formatted string
    AutoLink = Join(str)
    End Function

1 Trackbacks For This Post


  1. Autolink with classic asp & regular expression Says:

    [...] implementation of regular expression in Classic ASP script to create link from text (autolink), this is useful when you need to turn a bunch of text to be a clickable link when it is in a valid [...]

Leave a Reply