Last active
July 3, 2020 15:40
-
-
Save dardanxhymshiti/275d5ceb3a1445681540c154c4a7d6ef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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