fork download
  1. import re
  2. s = """some text here 45 [check {xyz}]
  3. more text 12 [check {pqr[25]}
  4. some more text 56 [check {efg[4]}]
  5. still more text 78 [check { jkl[12]}
  6. more text 123 [check abc]
  7. more text 34 ghi
  8. """
  9.  
  10. regex = r"(?<=check )(?:{[^{}]+}|[^\[\]]+)|\w+$"
  11.  
  12. l = re.findall(regex, s)
  13. print(l)
Success #stdin #stdout 0.03s 9528KB
stdin
Standard input is empty
stdout
['{xyz}', '{pqr[25]}', '{efg[4]}', '{ jkl[12]}', 'abc', 'ghi']