Skip to content

Instantly share code, notes, and snippets.

@mittenchops
Created February 12, 2014 19:45
Show Gist options
  • Save mittenchops/8963100 to your computer and use it in GitHub Desktop.
Save mittenchops/8963100 to your computer and use it in GitHub Desktop.
regexes for a number with an optional decimal place+decimal digits
# It took 15 tries.
digits = re.findall(r'[0-9]+', cleaned_text)
digits2 = re.findall(r'[0-9]\d*(\.\d+)?', cleaned_text)
digits3 = re.findall(r'[0-9]+((\.([0-9]+))?', cleaned_text)
digits4 = re.findall(r'[0-9]+(\.)?([0-9]+)?', cleaned_text)
digits5 = re.findall(r'\d+\.?\d*?', cleaned_text)
digits6 = re.findall(r'\d+(\.\d*)?', cleaned_text)
digits7 = re.findall(r'\d+(\.?\d*)?', cleaned_text)
digits8 = re.findall(r'\d+(\.?\d*)', cleaned_text)
digits9 = re.findall(r'\d+(\.{1}\d*)?', cleaned_text)
digits10 = re.findall(r'[0-9]+(\.{1}[0-9]+)?', cleaned_text)
digits11 = re.findall(r'^[0-9]\d*(\.\d+)?$', cleaned_text)
digits12 = re.findall(r'[0-9]+[\.{1}[0-9]+]?', cleaned_text)
digits13 = re.findall(r'[0-9]+[\.]?[0-9]?', cleaned_text)
digits14 = re.findall(r'[0-9]+(\.?[0-9]+)?', cleaned_text)
digits15 = re.findall(r'[0-9]+[\.]?[0-9]+', cleaned_text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment