Skip to content

Instantly share code, notes, and snippets.

@Bradysm
Created August 18, 2020 02:58
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 Bradysm/88b6cf3329b42533fc2b435e6a2ef3ba to your computer and use it in GitHub Desktop.
Save Bradysm/88b6cf3329b42533fc2b435e6a2ef3ba to your computer and use it in GitHub Desktop.
def find_all_numbers():
# create regex and then compile it into a regex object
regex = r'[+-]?\d+'
pattern = re.compile(regex)
# ask for an input from the user
input_str = input("Enter a string with numbers: ")
# find all numbers within the string using the regex
print("\nALL NUMBERS WITHIN THE STRING:")
for num in pattern.findall(input_str):
print(num)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment