Chapter 12 Example 3
♥0 |
Line 29 |
Modified 2009-07-23 05:37:54 |
MIT License
archived:2017-03-30 03:25:43
ActionScript3 source code
/**
* Copyright actionscriptbible ( http://wonderfl.net/user/actionscriptbible )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/npm8
*/
package {
import com.actionscriptbible.Example;
public class ch12ex3 extends Example {
public function ch12ex3() {
//IDENTIFYING
trace("---- exec()");
var contactNumbers:String =
"Call us at one of these numbers.\n" +
"Los Angeles: 310-555-2910\n" +
"New York: 212-555-2499\n" +
"Boston: 617-555-7141";
var phoneNumber:RegExp = /\d{3}-\d{3}-\d{4}/g;
var result:Object;
while(result = phoneNumber.exec(contactNumbers)) {
trace(result[0]); //prints out the phone numbers one by one
}
trace("---- match()");
var contactNumbers:String =
"Call us at one of these numbers.\n" +
"Los Angeles: 310-555-2910\n" +
"New York: 212-555-2499\n" +
"Boston: 617-555-7141";
var matches:Array = contactNumbers.match(/\d{3}-\d{3}-\d{4}/g);
if (matches) {
trace(matches.length); //3
trace(matches[0]); //310-555-2910
}
}
}
}