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2 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-0so I'm trying to find & select whole block of these text that contains
1.e4 e5 2.Nf3 Nc6 3.Bc4 Bc5 so if I search for it, it should select block1 & block3 altogether. I'm trying a pattern that may help but not able to construct it fully.
pattern is: \R\[Event (?:(?!\[Event)[\s\S])+1.e4 e5 2.Nf3 Nc6 3.Bc4 Bc5 \s\S\R(?!"\])
2 Answers
You're very close, just change the first \R at the beginning with ^ (beginning of line), escape the dots, and change the last part \s\S\R(?!"\]) into [\s\S]+?(?:\R\R|\z), see explanation below.
This will match the 2 occurrences in your example.
- Ctrl+F
- Find what:
^\[Event (?:(?!\[Event)[\s\S])+1\.e4 e5 2\.Nf3 Nc6 3\.Bc4 Bc5 [\s\S]+?(?:\R\R|\z) - check Wrap around
- check Regular expression
- Find All in Current Document
Explanation:
^ # 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 fileScreen capture:
0Use this search string :
^\[Event.*?\R.*?\R.*?\R.*?\R.*?\R.*?\R1\.e4 e5 2\.f4 exf4 3\.Nf3 g5 4\.h4 g4(?sm).*?(?=\R\R)Where:
^\[Event: matches[Eventat start of line.*?\R: non-greedy match of any up to and including newline, 6 time1\.e4 e5 2\.f4 exf4 3\.Nf3 g5 4\.h4 g4: string to search(?sm): turn on multi-line match.*?: non-greedy match of any character(?=\R\R): up until without including a blank line
Do NOT check the option of ". matches newline".
10