//Using Replace
var toungeTwister:String = "Peter Piper Picked a peck of pickled peppers";
//g is a global identifier so it doesn't stop only on the first match
var pickRegExp:RegExp = /pick|peck/g;
var replaced:String = toungeTwister.replace( pickRegExp, "Match");
//trace(replaced);
//Using Character Classes
var compassPoints:String = "Naughty Naotersn elephants squirt water";
var firstWordRegExp:RegExp = /N(a|o)/g;
//trace( compassPoints.replace( firstWordRegExp, "MATCH" ) );
var favoriteFruit = "bananas";
var bananaRegExp:RegExp = /b(an)+a/;
//trace( bananaRegExp.test( favoriteFruit ) );
//Exec() method returns an Object containing the groups that were matched
var htmlText:String = "<strong>This text is important</strong> while this text is not as important <strong>ya</strong>";
var strongRegExp:RegExp = /<strong>(.*?)<\/strong>/g;
var matches:Object = strongRegExp.exec( htmlText);
for( var i:String in matches ) {
//trace( i + ": " + matches[i] );
}
var email:String = "c@chrisaiv.comm";
var emailRegExp:RegExp = /^([a-zA-Z0-9_-]+)@([a-zA-Z0-9.-]+)\.([a-zA-Z]{2,4})$/i;
var catches:Object = emailRegExp.exec( email );
for( var j:String in catches ) {
//trace( j + ": " + catches[j] );
}
//trace( "This e-mail's validity is: " + emailRegExp.test( email ) );
//Test the validity of an e-mail
var validEmailRegExp:RegExp = /([a-z0-9._-]+)@([a-z0-9.-]+)\.([a-z]{2,4})/;
trace( validEmailRegExp.test( "a1a@c.info" ) );
//Return a Boolean if there is a pattern match
var phoneNumberPattern:RegExp = /\d\d\d-\d\d\d-\d\d\d\d/;
trace( phoneNumberPattern.test( "347-555-5555" )); //true
trace( phoneNumberPattern.test("Call 800-123-4567 now!")); //true
trace( phoneNumberPattern.test("Call now!")); //false
//Return the index number of the occurence is there is a pattern match
var themTharHills:String = "hillshillshillsGOLDhills";
trace(themTharHills.search(/gold/i)); //15