R – text matching in actionsript

actionscript-3flex3

Hi I have some html text coming from an rich text control.
something like:

<TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="Verdana" SIZE="10" COLOR="#0000FF"   LETTERSPACING="0" KERNING="0"><A HREF="event:http://bbc.co.uk" TARGET="_blank"><U>l</U></A><U>ink1</U><FONT COLOR="#000000"> blah blah blah. another <FONT COLOR="#0000FF"><A HREF="event:http://cnet.com" TARGET="_blank"><U>link2</U></A></FONT> blah blah</FONT></FONT></P></TEXTFORMAT>

I would like to extract all A tags ie:

<A HREF="event:http://cnet.com" TARGET="_blank"><U>link2</U></A>

Should I be looking into reg expressions or are there any string utils that would accomplish this.

Any hints/help much appreciated.

Best Answer

Yaa, You need to look into regular expressions because String utilities are basic String manipulation techniques. You can start with this:

var pattern:RegExp = /<A.*?</A>/;
var str:String = '<TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="Verdana" SIZE="10" COLOR="#0000FF"   LETTERSPACING="0" KERNING="0"><A HREF="event:http://bbc.co.uk" TARGET="_blank"><U>l</U></A><U>ink1</U><FONT COLOR="#000000"> blah blah blah. another <FONT COLOR="#0000FF"><A HREF="event:http://cnet.com" TARGET="_blank"><U>link2</U></A></FONT> blah blah</FONT></FONT></P></TEXTFORMAT>';
trace(pattern.exec(str));

It will output <A HREF="event:http://bbc.co.uk" TARGET="_blank"><U>l</U></A>.

Related Topic