fork download
  1. import re
  2.  
  3. string = """
  4. ** Hardware [0/1]
  5. - [ ] adapt a programmable motor to a tripod to be used for panning
  6. ** Reading - Technology [1/6]
  7. - [X] Introduction to Networking - Charles Severance
  8. - [ ] A Tour of C++ - Bjarne Stroustrup
  9. - [ ] C++ How to Program - Paul Deitel
  10. - [X] Computer Systems - Randal Bryant
  11. - [ ] The C programming language - Brian Kernighan
  12. - [ ] Beginning Linux Programming -Matthew and Stones
  13. ** Reading - Health [3/4]
  14. - [ ] Patrick McKeown - The Oxygen Advantage
  15. - [X] Total Knee Health - Martin Koban
  16. - [X] Supple Leopard - Kelly Starrett
  17. - [X] Convict Conditioning 1 and 2
  18. """
  19.  
  20. def getitems(section):
  21. rx = re.compile(r'^\*{2} ' + re.escape(section) + r'.+[\n\r](?P<block>(?:(?!^\*{2})[\s\S])+)', re.MULTILINE)
  22. try:
  23. items = rx.search(string)
  24. return items.group('block')
  25. except:
  26. return None
  27.  
  28. items = getitems('Reading - Technology')
  29. print(items)
Success #stdin #stdout 0.02s 27720KB
stdin
Standard input is empty
stdout
 - [X] Introduction to Networking - Charles Severance
 - [ ] A Tour of C++ - Bjarne Stroustrup
 - [ ] C++ How to Program - Paul Deitel
 - [X] Computer Systems - Randal Bryant
 - [ ] The C programming language - Brian Kernighan
 - [ ] Beginning Linux Programming -Matthew and Stones