I want to be able to manipulate the results of this regex and match it into groups so I can manipulate it. I get an error that says:
AttributeError: 'list' object has no attribute 'group'
My code is as follows:
sampleText= 'LOC OL85M132 LOC OL3M051'
matchLOC=re.findall(r'(LOC)\s([^\W\d_]{2})(\d+)M(\d{3})',sampleText)
for i in matchLOC:
print(i)
My result with this is:
('LOC', 'OL', '85', '132')
('LOC', 'OL', '3', '051')
This is fine but when I try and assign the groups to variables like:
MP=matchLoc.group(2)
Yards=matchLoc.group(3)
I get that error above. I want to:
1) Assign the third group to a variable 'MP'
2) Assign the fourth group to variable 'Yards'
From here on I would then like to do a series of manipulations. eg add the digit 0 to the end of the last number and also if-else loops such as
if Yards >= 130:
print('Yards = ' + str(int(Yards)-100))
print('MP = ' + str(int(MP) + 0.5))
and so on.