Skip to content

Instantly share code, notes, and snippets.

@dardanxhymshiti
Last active July 3, 2020 14:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dardanxhymshiti/24f460b330b388bfdf7d8722ada685e1 to your computer and use it in GitHub Desktop.
Save dardanxhymshiti/24f460b330b388bfdf7d8722ada685e1 to your computer and use it in GitHub Desktop.
def get_text_within_brackets(text):
import re
pattern = r"[\(|\[|\{](.*?)[\)|\]|\}]"
list_of_findings = re.findall(pattern, text)
return list_of_findings
# Test
text = '''I was very surprised (and it's pretty hard to surprise me!)... He [Felix] is a gret friends of me...'''
get_text_within_brackets(text)
# [ "and it's pretty hard to surprise me!", 'Felix' ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment