I'm trying to use regex expressions parse the numbers in strings with formats like this:
"R5+2-3"
Where the number after "R" is the total number of tests, the number after "+" is the number of positive tests, and the number after "-" is the number of negative tests. I'm trying to get the number of total tests, positive tests, and negative tests stored as integer values. I've tried using the following code:
ttl = 0
pos = 0
neg = 0
for matchttl in re.findall('R(\d+)', s):
ttl = ttl + int(matchttl)
for matchpos in re.findall('+(\d+)', s):
pos = pos + int(matchpos)
for matchneg in re.findall('-(\d+)', s):
neg = neg + int(matchneg)
Each expression works on its own, but when I use 2 or more expressions I get the following error:
File "C:\Users...", line 668, in _parse
raise source.error("nothing to repeat",
What am I doing wrong here?