Chapter 12 Example 2
♥0 |
Line 18 |
Modified 2009-07-23 05:35:05 |
MIT License
archived:2017-03-30 03:25:47
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/OBNF
*/
package {
import com.actionscriptbible.Example;
public class ch12ex2 extends Example {
public function ch12ex2() {
//SEARCHING
trace("---- search()");
var themTharHills:String = "hillshillshillsGOLDhills";
trace(themTharHills.search(/gold/i)); //15
trace("---- exec()");
var searchForGold:RegExp = /gold/gi;
var themTharHills:String = "hillsgoldhillshillsGOLDhills";
var result:Object = searchForGold.exec(themTharHills);
//TEST if there’s gold in the hills
if (result) trace("There's gold in them thar hills!");
//LOCATE the gold
trace(result.index); //5
//look a second time
result = searchForGold.exec(themTharHills);
//output the second location
trace(result.index); //19
}
}
}