# Regular Expression + \<a href\> + TextArea component

**URL:** <https://forum.kirupa.com/t/regular-expression-a-href-textarea-component/262353>\
**Category:** flash\
**Created:** [June 5, 2008, 11:05am UTC](https://forum.kirupa.com/t/regular-expression-a-href-textarea-component/262353 "2008-06-05T11:05:20Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![shubs6](https://avatars.discourse-cdn.com/v4/letter/s/a587f6/32.png) [@shubs6](https://forum.kirupa.com/u/shubs6)\
**Post date:** [June 5, 2008, 11:05am UTC](https://forum.kirupa.com/t/regular-expression-a-href-textarea-component/262353/1 "2008-06-05T11:05:20Z")

</div>

I’m using Regular expressions and \<a\> tag in my code to convert hyperlink input by the user (in TextArea component) displayed as that in another TextArea component.

My code is…

```auto

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">               
    <mx:Script>
        <![CDATA[       
            public function show():void           
            {                   
                var str:String = "";
                str = addHyperlink(inp.text);   
               
                if (out.htmlText == "") out.htmlText = str;
                else out.htmlText += str;
            }
             public function addHyperlink(inputStr:String):String
            {
                var regExp1:RegExp = new RegExp("(^|\\s+)((https?|ftp|news|)\\:\\/\\/[^\\s]*[^.,;''>\\s\\)\\]])" , "gi");
               
                if (regExp1.test(inputStr))                   
                    inputStr = inputStr.replace(regExp1 , "<a href='$2'> $2</a>");
                return inputStr;   
            }
           
        ]]>
    </mx:Script>
    <mx:TextArea id="out" x="146" y="31" width="215" height="58" />
    <mx:TextArea id="inp" x="146" y="119" width="215" height="56"/>
    <mx:Button x="224" y="199" label="click" click="show()"/>
    <mx:Label x="35" y="53" text="See OutPut Here"/>
    <mx:Label x="35" y="145" text="Input Text Here"/>
   
</mx:Application>

```

1).  
Give input in the lower TextARea as  
hiii [http://yahoo.com](http://yahoo.com)  
I am sorry - “hiii [http://yahoo.com](http://yahoo.com)” is not valid selection. Please try any one of following.

Button  
TextARea  
TextInput  
Chart  
HTML

2).  
Now Click the button named “click” to see the output.

3). delete text in the input box and type any text here. Say, you type “hi”.

You will see that a lot of text will disappear from output box. while debugging I found that its due to using $2 while replacing string.

Does anyone know a workaround?

Thanks in advance 🙂
