We Recommend

Essential ActionScript 3.0 Essential ActionScript 3.0
The book focuses on the core language and object-oriented programming, but also adds a deep look at the centerpiece of Flash Player's new API: display programming. Enjoy hundreds of brand new pages covering exciting new language features, such as the DOM-based event architecture, E4X, and namespaces--all brimming with real-world sample code.


Posted By

chrisaiv on 02/11/08


Tagged


Versions (?)


Who likes this?

1 person has marked this snippet as a favorite

outbox


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.