I am trying to write a regular expression to check moves in algebraic chess notation . Here is what I still have:
/
O-O(-O)?
|[KQRBN]x?[a-h][1-8]\+?
/
If I am lost, advance the pawn.
A knight, bishop, or center pawn can only advance on the file from which it is launched, or on both sides of the file through capture. The rook pawn can advance by moving straight or capturing in one direction, depending on whether it is on a- or h files. So something like
/[a-h](x[a-h])?[18]=[QRBN]\+?/
does not work because fxh8 is not a valid move (only fxe8 and fxg8). I could go a long route with
/(a(xb)?|h(xg)?|b(x[ac])?.../
. , - . - :
/([b-g])(x(\1±1))?/
, b , .