fork(1) download
  1. import re
  2. string = """
  3. aaa
  4.  
  5. aaa "word" --sdsdrrr2 --sds {
  6.  
  7. test test
  8. }
  9.  
  10. aaa "word2" --sdsdd sdsd {
  11.  
  12. fffsd
  13. ssss
  14. }
  15.  
  16. aaa "word3" -sdksdld sdsd
  17.  
  18. {
  19.  
  20. sdsdd
  21. sdsddd
  22. sdsdddd }
  23. """
  24.  
  25. rx = re.compile("""
  26. ^(?=.*"word2") # ^ - start of the line with pos. lookahead
  27. [^{]+ # anything not a {
  28. {[^}]+} # followed by {, anything in between and a closing }
  29. """, re.MULTILINE|re.VERBOSE)
  30.  
  31. matches = rx.findall(string)
  32. print matches
Success #stdin #stdout 0.01s 8968KB
stdin
Standard input is empty
stdout
['aaa "word2" --sdsdd sdsd {\n\n    fffsd\n    ssss\n}']