in reply to Parsing Chess Algebra Notation
If all you want to do is parse the individual moves (without validating, etc), the following regex will do the trick:
($p, $f, $r, $a, $d, $c) = $move =~ /([BKNPQR]?)([a-h]?)([0-9]?)([x=]?)([BKNPQR]|[a-h][1-8])([+#]?)/;
where the variables are as follows:
$move = the move being parsed
$p = the piece being moved
$f = the file being moved from
$r = the rank being moved from
$a = action (x = capture, '=' = promote)
$d = destination square (or promotion piece if $a = '=')
$c = check or mate
As an example, the move you gave, Nf4, will parse as follows:
$p = N, $f = "", $r = "", $a = "", $d = b4, $c = ""
hope this helps,
davidj