// $Id: regexmatch.ici,v 1.0 2003/01/03 12:07:00 dada Exp $
// http://dada.perl.it/shootout
//
// contributed by Tim Long

n := argv[1] ? int(argv[1]) : 1;
lines = gettokens(stdin, '\n', "");
j = 0;
while (--n)
{
    forall (l in lines)
    {
        a = l ~~~ #^[^\d(]*(?:\((\d\d\d)\)|(\d\d\d)) (\d\d\d)[ -](\d\d\d\d)(?:\D|$)#;
        if (n == 1 && a)
            printf("%d: (%s%s) %s-%s\n", ++j, a[0], a[1], a[2], a[3]);
    }
}

/*
 * The second last line of the test data is "foo (213 222-2222 bar", which
 * by my reading of the spec should match. But it is in the "shouldn't match"
 * section and no other programs matches it. So the above regexp is tailored
 * not to match it too.
 */