Return to Snippet

Revision: 80614
at March 23, 2020 05:12 by chrisaiv


Updated URL
https://www.chrisjmendez.com/2008/02/11/as3-regular-expression-basic-example/

Updated Code
https://www.chrisjmendez.com/2008/02/11/as3-regular-expression-basic-example/

Updated Description
https://www.chrisjmendez.com/2008/02/11/as3-regular-expression-basic-example/

Revision: 5105
at February 11, 2008 22:42 by chrisaiv


Initial Code
////////////////////////////////////////////
//Example 1: 
////////////////////////////////////////////

var re:RegExp = /<font face=\u0022(.*)\u0022 >(.*)<\/font>/i;
var str:String = '<P ALIGN="LEFT"><FONT FACE="Arial" >this is a test</FONT></P>';

var result:Object = re.exec(str);
trace(result[1]);//Arial
trace(result[2]);//this is a test

////////////////////////////////////////////
//Example 2: Replace all of the single quotes with double
////////////////////////////////////////////

var str2:String = "This 'is' the 'first' time 'ever'";
	str2 = str2.replace(/\u0027+/g, '"');
	trace(str2);

Initial URL

                                

Initial Description
The first example strips out the HTML.

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

Initial Title
AS3: Regular Expression Basic example

Initial Tags
regexp

Initial Language
ActionScript 3