In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

testing prime numbers with RegExp

Get Adobe Flash player
by makc3d 04 Nov 2013
    Embed
package {
    import com.actionscriptbible.Example;
    public class FlashTest extends Example {
        public function FlashTest() {
            // http://www.noulakaz.net/weblog/2007/03/18/a-regular-expression-to-check-for-prime-numbers/
            var r:RegExp = /^1?$|^(11+?)\1+$/;
            var u:String = "", s:String = "";
            for (var i:int = 1; i < 14; i++) {
                u += "1";
                s += i + " is " + (r.test (u) ? "not " : "") + "prime\n";
            }
            trace(s);            
        }
    }
}