in reply to tic-tac-toe regex golf

Your original fails in one case:

/^(...)*(X|O)\2\2|(X|­O)(.{2,3}\3)\4|^..(X­|O).\5.\5/ # ^^^^^^ ^^
The parts above ^s are the problem. They require that, in a '.X..X..X.' type of solution that the two '..' parts be the same. So it won't match '-XO-X-OX-' even though it should.

                - tye

Replies are listed 'Best First'.
Re: Re: tic-tac-toe regex golf (bug)
by barrachois (Pilgrim) on Nov 18, 2003 at 17:11 UTC
    Yes, thank you.

    That was just pointed out to me by someone else as well, and I've put an addendum and correction into the original post accordingly.

    Following Dave's suggestion to use \w instead of X|O, the shortest I'm currently aware of is this 57 char regex which lists out the two .{2,3} cases explicitly.

    ^(...)*(\w)\2\2|^..(\w).\3.\3|(\w)..\4..\4|(\w)...\5...\5
      Sometimes it helps to anchor from the other side:
      (\w)(..(\1|.\1.)..\1|.\1.\1..$|\1\1(...)*$)
      This 43 also gets rid of all those ugly different digits, in favor of pleasing uniformity :)