Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Regex will kill me solution in Clear category for Is String a Number? (Part II) by Kolia951
import re
def is_number(val: str) -> bool:
regex = r"^[+-]?(\d+\.{1}\d*|\d*\.{1}\d+|\d+)$"
result = re.search(regex, val)
return bool(result)
print("Example:")
print(is_number("10"))
# These "asserts" are used for self-checking
assert is_number("34") == True
assert is_number("df") == False
assert is_number("") == False
assert is_number("+10.0") == True
assert is_number("1OOO") == False
assert is_number("1.") == True
assert is_number("+.l") == False
print("The mission is done! Click 'Check Solution' to earn rewards!")
Dec. 12, 2022
Comments: