Hi guys i have this text
US Championships
----------------
[Event "ch-USA sf"]
[Site "Denver USA"]
[Date "1998.11.10"]
[Round "01"]
[White "Shaked,T"]
[Black "DeFirmian,N"]
[Result "1/2-1/2"]
[ECO "A30"]
[WhiteElo "2490"]
[BlackElo "2605"]
1. c4 c5 2. Nf3 Nc6 3. Nc3 Nf6 4. g3 b6 5. Bg2 Bb7 6. O-O e6 7. e4 d6 8. d4
cxd4 9. Nxd4 Nxd4 10. Qxd4 Be7 11. b3 O-O 12. Ba3 Qc7 13. Rfd1 Rfd8 14. Nb5
Qc6 15. Qe3 Ne8 16. Bb4 a6 17. Nd4 Qc7 18. a4 Nf6 19. a5 Re8 20. Ne2 bxa5
21. Bxa5 Qc6 22. Nc3 Rab8 23. h3 Ba8 24. Rab1 Bd8 25. Bxd8 Rexd8 26. f4 h6
27. Rb2 Qc7 28. Kh2 Bc6 29. Rd4 a5 30. Qd2 Kf8 31. Qd1 e5 32. fxe5 dxe5 33.
Rxd8 Rxd8 34. Rd2 Rb8 35. Nd5 Bxd5 36. exd5 Qc5 37. Qc2 h5 38. Qc3 e4 39.
Re2 a4 40. bxa4 Nxd5 41. Qe5 Rb1 42. h4 Qg1 43. Kh3 Nf6 44. Bxe4 Nxe4
1/2-1/2
7th Monarch Assurance
---------------------
[Event "7th Monarch Assurance"]
[Site "Port Erin IOM"]
[Date "1998.11.09"]
[Round "03"]
[White "Plaskett,J"]
[Black "Sutovsky,E"]
[Result "0-1"]
[ECO "B50"]
[WhiteElo "2455"]
[BlackElo "2575"]
1. e4 c5 2. Nf3 d6 3. Bc4 Nf6 4. Nc3 a6 5. d3 Nc6 6. a3 g6 7. O-O Bg7 8. h3
b5 9. Ba2 O-O 10. Bg5 h6 11. Be3 e5 12. Qd2 Nd4 13. Nh2 Kh7 14. f4 Be6 15.
Bxe6 fxe6 16. fxe5 dxe5 17. g4 Nd7 18. Rxf8 Qxf8 19. Rf1 Qe7 20. g5 h5 21.
Ne2 b4 22. axb4 cxb4 23. Nf3 Qc5 24. Nexd4 exd4 25. Bf4 a5 26. b3 a4 27.
bxa4 Rxa4 28. Qd1 Ra2 29. Rf2 Qc3 30. Kg2 Nc5 31. Rd2 b3 32. cxb3 Qxd3 33.
Qe1 Qxb3 34. e5 d3 35. Rxa2 Qxa2 36. Qf2 Qd5 37. Qd4 Qxd4 38. Nxd4 Bxe5
0-1
the text above is a sample! I'm trying hard to find a regex that will find all of
Some Text
----------------
Lines and remove them using python!
I'm trying hard to find regex match of these both lines so I can remove them The amount of the -- is random but its absolutely more than 1 and I only want to match two lines not any more things
So from the example text I want these matches
US Championships
----------------
7th Monarch Assurance
---------------------
Can you guys please help me I tried many ways but no success
CodePudding user response:
Try (text
is your text from the question) regex demo:
import re
pat = re.compile(r"^.*\n- $", flags=re.M)
for m in pat.findall(text):
print(m)
Prints:
US Championships
----------------
7th Monarch Assurance
---------------------