fork download
  1. import re
  2.  
  3. textToSearch = """
  4. hello{
  5. @hi {
  6. I want this text
  7. }
  8.  
  9. @hola {
  10. I don't want this text
  11. }
  12. }
  13. """
  14.  
  15. regex= r'[^\S\r\n]*@hi\b[^\S\r\n]*{[^{}]*}'
  16. result = re.findall(regex,textToSearch)
  17.  
  18. print(result)
Success #stdin #stdout 0.02s 9408KB
stdin
Standard input is empty
stdout
['    @hi {\n        I want this text\n    }']