Detect Floating Point Number

  • + 0 comments

    This prints True for '0' when I submit code

    print(True if re.match(r"^[-+\.]?\d*\.\d*$", input()) else False)
    

    This prints False for '0' when I submit code

    print(True if re.match(r"^[-+\.]?\d*\.?\d*$", input()) else False)
    

    what am I missing here?

    It should be the reverse, i.e. second statement above should be "True" (see regex101.com link) https://regex101.com/r/dIOXFe/1