Skip to content

Instantly share code, notes, and snippets.

@carlosdiaz
Created October 1, 2015 02:43
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 carlosdiaz/bbaa986329be1674d8fd to your computer and use it in GitHub Desktop.
Save carlosdiaz/bbaa986329be1674d8fd to your computer and use it in GitHub Desktop.
Based on json representation http://www.json.org/number
import re
str = '-1.95'
#str = '0.3456'
#str = '1.341516'
#str = '0.89788'
#yes, large regular expression but seems it solves, tested with different scenarios
pattern = re.compile(r'''^((-\d*)(.\d*)|(0.\d*)|((0.\d*(e|E)(\+|\-)\d))|((-\d*)(.\d*))(((e|E)(\+|\-)\d)))$''', re.VERBOSE)
print pattern.match(str)
if match:
print 'found', match.group()
else:
print 'did not find'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment