Write five regular expressions:
integers that will match all whole numbers, positive or negative.floats that will match all decimal numbers, positive or negative.positive that will match all positive numbers, whole or decimal.negative that will match all negative numbers, whole or decimal.numbers that will match all numbers, whole or decimal, positive or negative.Details to take into account:
0.5, .5, -.5 and are valid numbers.4. and -3. are not valid numbers.+. Both 3 and +3 are valid numbers.++1, -+4, 3.3.6 are not valid numbers.txt = " 123.456 2 +7 -88 -.25 9.10.11 -4. +-34 -0.6 --5 "
integers = "yourregularexpressionhere"
floats = "yourregularexpressionhere"
positive = "yourregularexpressionhere"
negative = "yourregularexpressionhere"
numbers = "yourregularexpressionhere"
re.findall(integers, txt) ➞ ["2", "+7", "-88"]
re.findall(floats, txt) ➞ ["123.456", "-.25", "-0.6"]
re.findall(positive, txt) ➞ ["123.456", "2", "+7"]
re.findall(negative, txt) ➞ ["-88", "-.25", "-0.6"]
re.findall(numbers, txt) ➞ ["123.456", "2", "+7", "-88", "-.25", "-0.6"]
You don't need to write a function, just the pattern.
Do not remove import re from the code.
If you get stuck, check Comments for some helpful hints.
You can find all the challenges of this series in my Basic RegEx collection.