我正在尝试为PGN文件移动创建解析器。我想从移动1开始的总文本输入中提取一个子字符串。
这是 PGN 文件的示例部分:
我试图通过正则表达式在使用中提取移动。substring
indexOf()
这是我的尝试:
function extractMoves(){
const pgn = '[Date "2013.11.12"] 1.Nf3 d5 2.g3 g6'; // Sample PGN.
const firstMove = /1\.([a-h]|[NBRQK])/; // First move regex.
const moves = pgn.substring(pgn.indexOf(firstMove));
return moves;
}
console.log(extractMoves());
这是预期的输出:
1.Nf3 d5 2.g3 g6
ABOUTYOU
相关分类