Your pattern [^_] matches any character that is not an underscore.
Use (..|..) or a grouping instead:
float(re.findall('(?:^|_)' + par + r'(\d+\.\d*)', dir)[0])
I used there a group (?:..) non-captureuring so that it does not interfere with your original group indices.
Demo:
>>> import re >>> dir = 'a1.8000_b1.0000_cc1.3000_al0.209_be0.209_c1.344_e0.999' >>> par = 'e' >>> re.findall('(?:^|_)' + par + r'(\d+\.\d*)', dir) ['0.999'] >>> par = 'a' >>> re.findall('(?:^|_)' + par + r'(\d+\.\d*)', dir) ['1.8000']
To develop using a group of characters ( [..] ), and you start this group with a carriage ( ^ ), you invert the group of characters by flipping it from matching the specified characters to match all the others:
>>> re.findall('[a]', 'abcd') ['a'] >>> re.findall('[^a]', 'abcd') ['b', 'c', 'd']
source share