【发布时间】:2020-10-03 10:18:13
【问题描述】:
我有一个 PGN,其中包含如下文本。我只想提取第一场比赛,所以直到第二个 [Event] 标记使用正则表达式。即使打开了多行标签,我在 regex101.com 上的尝试似乎也失败了多行。例如:
\[Event.*\n*
只捕获第一行
任何帮助表示赞赏。
编辑:
给定的答案\A\[Event.*(?:\r?\n(?!\[Event).*)* 完美运行,但我遇到了一个破坏正则表达式的 pgn 文件。我已经删除了旧示例并放入了新示例。例如,有一个标签是[Eventdate "2009.12.09"],所以现在正则表达式需要查找下一个不是[Eventdate的[Event ...
示例 pgn 文件:
[Event "Hastings"]
[Site "Hastings ENG"]
[Date "1895.08.17"]
[Round "10"]
[White "Wilhelm Steinitz"]
[Black "Curt von Bardeleben"]
[Result "1-0"]
[ECO "C54"]
[EventDate "1895.08.05"]
[PlyCount "48"]
1.e4 e5 2.Nf3 Nc6 3.Bc4 Bc5 4.c3 Nf6 5.d4 exd4 6.cxd4 Bb4+ 7.Nc3 d5 8.exd5 Nxd5 9.O-O Be6 10.Bg5 Be7 11.Bxd5 Bxd5 12.Nxd5 Qxd5 13.Bxe7 Nxe7 14.Re1 f6 15.Qe2 Qd7 16.Rac1 c6 17.d5 cxd5 18.Nd4 Kf7 19.Ne6 Rhc8 20.Qg4 g6 21.Ng5+ Ke8 22.Rxe7+ Kf8 23.Rf7+ Kg8 24.Rg7+ Kh8 25.Rxh7+
[Event "FICS rated standard game (FICS, San Jose"]
[Site "California USA)"]
[Date "2009.12.09"]
[Round "?"]
[White "Damo"]
[Black "Dalvero"]
[Result "0-1"]
[PlyCount "16"]
[WhiteElo "1565"]
[BlackElo "1465"]
1. e4 e5 2. Nf3 Nc6 3. Bc4 Bc5 4. Nc3 d6 5. h3 Nf6 6. Ng5 O-O 7. d3 Nd4 8. Bd2
Be6 0-1 {White forfeits by disconnection}
【问题讨论】:
-
\A\[Event.*(?:\r?\n(?!\[Event).*)*regex101.com/r/aiEmsk/1
标签: regex