Wednesday, 8 January 2020

The joy of regular expressions

There is a claim that you are not a real programmer unless you can build regular expressions. Occasionally I have need for them in a professional capacity, but doing them on the fly is always a difficult task for me.
My most recent problem was that the pgn files from the 2020 Australian Championship had the clock times included as comments. Normally this isn't a problem as you can strip comments using chessbase, but as I don't have that on my laptop, it required a different solution (that wasn't manual deletion).  \{[\s\S]*?}\s was the magic incantation used in Brackets, which was sufficient to get the file into something I could use more easily. And as proof, here is a nice win by Jack Puccini from yesterdays round.

Puccini, Jack - O`Chee, Kevin
2020 Australian Championship , 2020.01.07

Start positionPrevious MoveNext MoveEnd positionPlay movesStop playing
1. e4 c5 2. Nf3 e6 3. d4 cxd4 4. c3 dxc3 5. Nxc3 Nc6 6. Bc4 a6 7. O-O Nge7 8. Bg5 Qc7 9. Nd5 exd5 10. exd5 Ne5 11. d6 Nxf3+ 12. Qxf3 Qxc4 13. dxe7 Bxe7 14. Rac1 Qxa2 15. Bxe7 Kxe7 16. Rfe1+ Kf8 17. Qc3 f6 18. Qb4+ d6 19. Qxd6+ Kf7 20. Rc7+ Kg6 21. Qg3+ Kh5 22. Qxg7 Qa5 23. Qf7+ Kg5 24. h4+ Kxh4 25. Qxf6+ Qg5 26. Re4+ Bg4 27. Rxg4+ Kxg4 28. Qf3+ 1-0

No comments: