0

So I am trying to develop an app that requires a feature where it's able to detect numbers in a string that are not attached to letters.

Currently, this is the regex sequence I am using

foundNumber = bool(re.findall(r'\d+(?:,\d+)?', "I have 10 cats"))

For example, if we execute the above line, foundNumber = true, which is what I want.

But when I have this string:

foundNumber = bool(re.findall(r'\d+(?:,\d+)?', "I use 3D modeling."))

The regex sequence goes "Hey! I found a 3!" Whereas it's a false positive. foundNumber = true, whereas it should equal false.

Lastly, if I have this sequence:

foundNumber = bool(re.findall(r'\d+(?:,\d+)?', "I have 10 cats and I love 3D modeling"))

I should get a true value back since I still have 10 cats.

Can someone help me with my regex? I'm a beginner with regex, so any help would be appreciated, thanks!!!

0 Answers0