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nf6 20.Qg3 Qxg3+ 21.Nxg3 c4 22.Rfd1 cxd3
23.Bxd3 a5 24.Bc2 Rxd1 25.Bxd1 Rd8 26.Be2 Ne8 27.Nf1 Nd6 28.Nd2 f6 29.Kg1 Kf7
30.Kf1 Ke7 31.Ke1 Bf7 32.f3 Be6 33.Bf2 g6 34.b3 Kf7 35.Bd3 Nc8 36.Ke2 N8e7
37.h4 h5 38.Be3 Rd7 39.a3 Rd8 40.a4 Ra8 41.Nc4 Rd8 42.Rg1 Nc8 43.Rb1 Nd6
44.Nxd6+ Rxd6 45.Kd2 Ne7 46.Kc2 Bd7 47.Rg1 Be6 48.Be2 Rd8 49.Rf1 Nc8 50.f4 Nd6
51.Bd3 exf4 52.Bxf4 Ne8 53.Bb5 Nd6 54.Bc6 Kg7 55.e5 Bf5+ 56.Kb2 Nf7 57.exf6+ Kxf6
58.g3 Rc8 59.Re1 Rd8 60.Bxc7 Rc8 61.Bxb6 1-0
所以我试图找到并选择包含这些文本的整个块
1.e4 e5 2.Nf3 Nc6 3.Bc4 Bc5
所以如果我搜索它,它应该会同时选择 block1 和 block3。我正在尝试一种可能有帮助但无法完全构建它的模式。
模式是:\R\[Event (?:(?!\[Event)[\s\S])+1.e4 e5 2.Nf3 Nc6 3.Bc4 Bc5 \s\S\R(?!"\])
答案1
\R
您已经非常接近了,只需将开头的第一个更改为^
(行首),转义点,并将最后一部分更改\s\S\R(?!"\])
为[\s\S]+?(?:\R\R|\z)
,请参阅下面的解释。
这将匹配您示例中的 2 个出现的情况。
- Ctrl+F
- 找什么:
^\[Event (?:(?!\[Event)[\s\S])+1\.e4 e5 2\.Nf3 Nc6 3\.Bc4 Bc5 [\s\S]+?(?:\R\R|\z)
- 检查环绕
- 检查正则表达式
- Find All in Current Document
解释:
^ # beginning of line
\[Event # literally
(?: # starqt tempered greedy token
(?!\[Event) # negative lookahead, make sure we haven't [Event
[\s\S] # any character included linebreak
)+ # 1 or more times
1\.e4 e5 2\.Nf3 Nc6 3\.Bc4 Bc5 # literally
[\s\S]+? # 1 or more any character included linebreak, not greedy
(?:\R\R|\z) # non capture group, double linebreak or end of file
屏幕截图: