I am trying to detect all integers and whole numbers (among a lot of other things) from a string. Here are the regular expressions I am currently using:
Whole numbers: r"[0-9]+"
Integers: r"[+,-]?[0-9]+"
Here are the issues:
- The whole numbers regex is detecting negative numbers as well, which I cannot have. How do I solve this? If I use a space before at start of the regex I get only positive numbers, but then I get a space at the start of my output!
- For whole numbers, I would like to detect positive numbers with the format
+[0-9]
but store them without the sign. - For integers, I would like to store any positive integer detected with the sign, irrespective if it is present in the original string.
Almost done now: One last thing, I have a string that says "Add 10 and -15". I want to store the integers in a list. I do so using the findall(). While storing the numbers is it possible to store '10' as '+10'