Regex to match something based on what was matched before
问题 I'm trying to write a regular expression to validate moves in algebraic chess notation. Here's what I have so far: / O-O(-O)? # Castling |[KQRBN]x?[a-h][1-8]\+? # Most normal moves and captures / Where I am lost is pawn promotion. A knight, bishop, or centre pawn may only promote on the file from which it starts or the file on either side via a capture. A rook pawn may promote by moving straight or capturing to one side, depending on whether it is on the a- or h- files. So something like /[a