Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 308089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:37:06+00:00 2026-05-12T07:37:06+00:00

I have a text that I want to linkify (identify URLs and convert them

  • 0

I have a text that I want to linkify (identify URLs and convert them to HTML links). The text could be multi-line, and could contain multiple urls like the example below.

My current actionscript code looks like this

<mx:Script>
    <![CDATA[

    import mx.controls.Alert;
    import mx.rpc.events.FaultEvent;      
    import mx.rpc.events.ResultEvent;


    private function init():void {
        var str:String = "@stack the website for google is http://www.google.com and gmail is http://gmail.com";

        //Alert.show(linkify(str),"Error");
        txtStatus.htmlText = linkify(str);
    }

     private function linkify(texty:String):String {
        //return texty.replace("/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+/g",function(m):String { return m.linkify(m);});
        //return texty.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+/g, function(m):String {return m.linkify(m);}).replace(/(^|[^\w])(@[\d\w\-]+)/g, function(m2):String{return '@<a href="http://twitter.com/' + m2.substr(1) + '">' + m2.substr(1) + '</a>'; });
        var pattern:RegExp = /[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+/g;
        var match:String = pattern.exec(texty);
        return texty.replace(pattern,'<a href="' + match + '">' + 
        match + '</a>');
    }

    ]]>
</mx:Script>

The problem with the above script is that it recognizes the first match and uses that across. Also how do i do it for @?

Any help is highly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T07:37:07+00:00Added an answer on May 12, 2026 at 7:37 am

    ooph … why does everybody use regex these days, to accomplish super simple tasks? also, you forgot, that “+” is a valid character for URLs, as a replacement for space, and even an awful lot of other characters may be used, so your pattern would not even match accordingly …

    well, anyway, have a look at AS3 regex metacharacters …
    that’ll GREATLY improve your expression’s readability and is much more robust…

    i’d go with something like this, really:

    var r:RegExp = /(?:http|https):\/\/\S*/g;
    trace(str.replace(r, function (s:String,...rest):String { 
        return '<a href="' + s + '">' + s + '</a>' 
    } ));
    

    but the actual point, was the global flag …

    good luck then … 🙂

    greetz

    back2dos

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some text that has HTML hyper-links in it. I want to remove
I have a text file that I want to read line by line and
Let's say I have this text that I want to display in an HTML
I have a text file that I want to edit by rewriting it to
I have a text file that I want to edit using Java. It has
I have a text file that I want to send over the network, this
I have old text inside a div. I want that text to fly out
I have some text/images that I only want to display in the normal state
I have around 100 rows of text that I want to tokenize, which are
I have a file with Chinese text that I want to use in my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.