Skip to content

Instantly share code, notes, and snippets.

@dardanxhymshiti
Last active July 3, 2020 15:40
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/275d5ceb3a1445681540c154c4a7d6ef to your computer and use it in GitHub Desktop.
Save dardanxhymshiti/275d5ceb3a1445681540c154c4a7d6ef to your computer and use it in GitHub Desktop.
def get_numbers_from_text(text):
import re
pattern = '[-+]?[.]?[\d]+(?:,\d\d\d)*[\.]?\d*(?:[eE][-+]?\d+)?'
list_of_numbers = re.findall(pattern, text)
return list_of_numbers
# Test
text = """A rise in cases was re[prted acrpss a staggering 36 US states last week. In Florida, officals recorded 9,585 new cases on Saturday."""
get_numbers_from_text(text)
# ['36', '9,585']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment