regx = re.compile("""^(PART.*)(
(\\d*).*\\s(\\d+)
)""", re.MULTILINE)

def repl(mat):
    return ''.join((mat.group(1), ' ', str(int(mat.group(4)) - int(mat.
        group(3))), mat.group(2)))
for mat in regx.finditer(ss):
    print(mat.groups())
print() 
print(regx.sub(repl, ss))
Arithmetic operations in regex