Last active
March 20, 2016 08:43
-
-
Save Lvl4Sword/b973a436d3ed21095e2c to your computer and use it in GitHub Desktop.
Find Numbers In A String
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
# This finds positive, negative, and float numbers. | |
# They're added into a list by what was found first | |
# and then presented to the user. | |
# Let me know if you find any issues. | |
import re | |
# this prints ['0', '-10', '10.0', '10.999999999999999'] | |
# which is what's expected :-) | |
the_string = "single 0 // negative -10 // float 10.0 // long float 10.999999999999999" | |
pattern = re.compile(r"(-?\d+(?:\.\d+)?)") | |
numbers_found = pattern.findall(the_string) | |
print(numbers_found) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment