fork download
  1. import re
  2.  
  3. regex = r"^\|[^\w\|]*(\w+\s+(?=\w+)[^\|]*)"
  4.  
  5. test_str = ("------------------------------------------------------------\n"
  6. "#2016-12-24\n"
  7. "| 单词 | 解释 | 例句 |\n"
  8. "| --------- | -------- | --------- |\n"
  9. "|**accelerator;**| - | - |\n"
  10. "|**compass**| - | - |\n"
  11. "|**wheels**| - | - |\n"
  12. "|**fabulous**| - | - |\n"
  13. "|**sweeping**| - | - |\n"
  14. "|**prospect**| - | - |\n"
  15. "|**pumpkin**| - | - |\n"
  16. "|**trolley**| - | - |\n"
  17. "|snapped,**| - | - |\n"
  18. "|tip| - | - |\n"
  19. "|lap| - | - |\n"
  20. "|tether.| - | - |\n"
  21. "|damp| - | - |\n"
  22. "|triumphant| - | - |\n"
  23. "|sarcastic| - | - |\n"
  24. "|missed out| - | - |\n"
  25. "|sidekick| - | - |\n"
  26. "|considerable| - | - |\n"
  27. "|Willow.| - | - |\n"
  28. "|eagle.| - | - |\n"
  29. "|considerably.| - | - |\n"
  30. "|flat.| - | - |\n"
  31. "|feast| - | - |\n"
  32. "|scramble| - | - |\n"
  33. "|turned up| - | - |\n"
  34. "|rounded off| - | - |\n"
  35. "|rat| - | - |\n"
  36. "|resembled| - | - |\n"
  37. "|By the time she had clambered back into the car,| - | - |\n"
  38. "|By the time she had clambered back into the car, they were running very late,| - | - |\n"
  39. "|wheeled his trolley| - | - |\n"
  40. "|barrier,| - | - |\n"
  41. "|bounced| - | - |\n"
  42. "|in blazes| - | - |\n"
  43. "|clutching| - | - |\n"
  44. "|sealed| - | - |\n"
  45. "|stunned.| - | - |\n"
  46. "|‘We’re stuck,| - | - |\n"
  47. "|marched off| - | - |\n"
  48. "|accelerator| - | - |\n"
  49. "|and the prospect of seeing Fred and George’s jealous faces| - | - |\n"
  50. "|protest.| - | - |\n"
  51. "|in protest.| - | - |\n"
  52. "|horizon,| - | - |\n"
  53. "|knuckles| - | - |\n"
  54. "|metal| - | - |\n"
  55. "|thick| - | - |\n"
  56. "|reached the end of its tether.| - | - |\n"
  57. "|Artefacts| - | - |\n"
  58. "|blurted out.| - | - |\n"
  59. "|gaped| - | - |\n"
  60. "|I will be writing to both your families tonight.| - | - |\n"
  61. "|‘Can you believe our luck, though?’| - | - |\n"
  62. "|‘Skip the lecture,’| - | - |\n"
  63. "|people’ll be talking about that one for years!’| - | - |\n"
  64. "|nudged| - | - |\n"
  65. "|‘I know I shouldn’t’ve enjoyed that or anything, but –’| - | - |\n"
  66. "|dashed| - | - |\n"
  67. "------------------------------------------------------------")
  68.  
  69. matches = re.finditer(regex, test_str, re.MULTILINE)
  70.  
  71. for matchNum, match in enumerate(matches):
  72. print(match.group(1))
  73.  
  74.  
  75.  
Success #stdin #stdout 0.02s 27720KB
stdin
Standard input is empty
stdout
missed out
turned up
rounded off
By the time she had clambered back into the car,
By the time she had clambered back into the car, they were running very late,
wheeled his trolley
in blazes
marched off
and the prospect of seeing Fred and George’s jealous faces
in protest.
reached the end of its tether.
blurted out.
I will be writing to both your families tonight.
Can you believe our luck, though?’
Skip the lecture,’
I know I shouldn’t’ve enjoyed that or anything, but –’