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…
<?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
I am sorry - “hiii 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