fork download
  1. texts = [
  2. "Hello(Hi()) more text",
  3. "Hello(Hi) more text",
  4. "Hello(Hi() , Bye(bye) , Foo) more text",
  5. ]
  6.  
  7. import re
  8.  
  9. for text in texts:
  10. matches = re.match(r'^%s\s*\(((?:[^()]*|\([^)]*\))*)\)' % re.escape("Hello"), text)
  11. print matches.group(1)
Success #stdin #stdout 0.02s 4676KB
stdin
Standard input is empty
stdout
Hi()
Hi
Hi() , Bye(bye) , Foo