$re = '/(\d+\.)\s+([\w\-#]+)\s+(\{[^\}]+\})\s+\1\.+\s+([\w\-#]+)\s+(\{[^\}]+\})/m';
$str = '[Event "Live Chess"]
[Site "Chess.com"]
[Date "2018.12.07"]
[Round "-"]
[White "Joerg64"]
[Black "Damir_Khamzin"]
[Result "0-1"]
[WhiteElo "1317"]
[BlackElo "1312"]
[TimeControl "1800"]
[EndTime "9:36:56 PST"]
[Termination "Damir_Khamzin поставил мат"]
1. d4 {[%clk 0:29:59.9]} 1... d5 {[%clk 0:29:57.6]} 2. c4 {[%clk 0:29:50.5]}
2... e6 {[%clk 0:29:52.9]} 3. a3 {[%clk 0:29:46.5]} 3... h6 {[%clk 0:29:27.5]}
4. Nc3 {[%clk 0:29:44.3]} 4... Nf6 {[%clk 0:29:24.7]} 5. h3 {[%clk 0:29:41.2]}
5... Nbd7 {[%clk 0:29:07.7]} 6. Nf3 {[%clk 0:29:23.2]} 6... Be7 {[%clk 0:28:59]}
7. e3 {[%clk 0:29:17.7]} 7... b6 {[%clk 0:28:49.7]} 8. Bd3 {[%clk 0:29:05.4]}
8... Bb7 {[%clk 0:28:39]} 9. b4 {[%clk 0:28:29.3]} 9... c5 {[%clk 0:28:01.5]}
10. b5 {[%clk 0:28:18.5]} 10... dxc4 {[%clk 0:27:46.4]} 11. Bxc4 {[%clk
0:28:15.2]} 11... cxd4 {[%clk 0:27:38]} 12. exd4 {[%clk 0:27:57.6]} 12... O-O
{[%clk 0:27:28.5]} 13. O-O {[%clk 0:27:54.6]} 13... Qc7 {[%clk 0:27:05.4]} 14.
Re1 {[%clk 0:26:46.2]} 14... Qxc4 {[%clk 0:26:28.7]} 15. Ne5 {[%clk 0:26:11.3]}
15... Qxc3 {[%clk 0:26:04.9]} 16. Bf4 {[%clk 0:25:46.4]} 16... Nxe5 {[%clk
0:25:52.3]} 17. dxe5 {[%clk 0:25:38.1]} 17... Nd5 {[%clk 0:25:40.1]} 18. Bh2
{[%clk 0:25:27.6]} 18... Bxa3 {[%clk 0:24:33]} 19. Rb1 {[%clk 0:24:42.4]} 19...
Bc5 {[%clk 0:24:13.6]} 20. Re2 {[%clk 0:24:27.9]} 20... Qd4 {[%clk 0:22:45.6]}
21. Rd2 {[%clk 0:24:21.1]} 21... Qh4 {[%clk 0:22:39.6]} 22. Bg3 {[%clk
0:24:14.8]} 22... Qe7 {[%clk 0:22:35.3]} 23. Rc2 {[%clk 0:20:18.6]} 23... Rad8
{[%clk 0:21:55]} 24. Qg4 {[%clk 0:20:10.7]} 24... Qg5 {[%clk 0:21:18.3]} 25. Qa4
{[%clk 0:19:52.9]} 25... Qg6 {[%clk 0:20:48.8]} 26. Kh1 {[%clk 0:19:22.1]} 26...
Nb4 {[%clk 0:20:21.5]} 27. Rcb2 {[%clk 0:18:39.8]} 27... Ra8 {[%clk 0:19:41.5]}
28. Rxb4 {[%clk 0:18:22.8]} 28... Bxb4 {[%clk 0:19:38.6]} 29. Qxb4 {[%clk
0:18:14.3]} 29... Qe4 {[%clk 0:19:22.3]} 30. Qb2 {[%clk 0:17:43.9]} 30... Qxg2#
{[%clk 0:19:15.9]} 0-1
';
$subst = "\n\1 \2 \4 \3 - \5";
$result = preg_replace($re, $subst, $str);
echo "The result of the substitution is ".$result;
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php