我正在嘗試為PGN文件移動創建解析器。我想從移動1開始的總文本輸入中提取一個子字符串。這是 PGN 文件的示例部分:斷續器我試圖通過正則表達式在使用中提取移動。substringindexOf()這是我的嘗試: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
使用正則表達式提取子字符串
烙印99
2022-09-16 21:03:56