As you guessed correctly, this has to do with capturing groups. According to the documentation for re.findall
:
If one or more groups are present in the pattern, return a list of groups
Therefore, you need to make all your groups ()
non-capturing using the (?:)
specifier. If there are no captured groups, it will return the entire match:
>>> pattern = r'(?:\d*\.)?\d+'
>>> findall(pattern, s)
['7.95', '10']
6
solved Regex behaving weird when finding floating point strings [duplicate]