← Back to challenges

RegEx Exercise #6: Float Number

PythonHardregexstringslogicvalidation

Instructions

Create a regular expression to check whether the given string is a valid floating numeric character or not.

Examples

pattern = "yourregularexpressionhere"

bool(re.match(pattern, "12.12")) ➞ True
bool(re.match(pattern, "12.")) ➞ False
bool(re.match(pattern, ".1")) ➞ True
bool(re.match(pattern, "-.1")) ➞ True
bool(re.match(pattern, "+4.4")) ➞ True
bool(re.match(pattern, "+4")) ➞ False
bool(re.match(pattern, "+4.4av")) ➞ False

Notes

  • You don't need to write a function, just the pattern.

  • Do not remove import re from the code.

  • You can find all the challenges of this series in my Basic RegEx collection.

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: ASCII Art!