Posted By

chrisaiv on 02/11/08


Tagged

regexp as3


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

outbox
THEPWN3R
tspitzr


AS3: Regular Expression Basic example


 / Published in: ActionScript 3
 

The first example strips out the HTML.

The second example shows how to target a single quote using unicode.

  1. ////////////////////////////////////////////
  2. //Example 1:
  3. ////////////////////////////////////////////
  4.  
  5. var re:RegExp = /<font face=\u0022(.*)\u0022 >(.*)<\/font>/i;
  6. var str:String = '<P ALIGN="LEFT"><FONT FACE="Arial" >this is a test</FONT></P>';
  7.  
  8. var result:Object = re.exec(str);
  9. trace(result[1]);//Arial
  10. trace(result[2]);//this is a test
  11.  
  12. ////////////////////////////////////////////
  13. //Example 2: Replace all of the single quotes with double
  14. ////////////////////////////////////////////
  15.  
  16. var str2:String = "This 'is' the 'first' time 'ever'";
  17. str2 = str2.replace(/\u0027+/g, '"');
  18. trace(str2);

Report this snippet  

You need to login to post a comment.