I am trying to add a number from a backreference to another number, but I seem to get only concatenation:
textStr = "<testsuite errors=\"0\" tests=\"4\" time=\"4.867\" failures=\"0\" name=\"TestRateUs\">"
new_str = textStr.gsub(/(testsuite errors=\"0\" tests=\")(\d+)(\" time)/, '\1\2+4\3')
# => "<testsuite errors=\"0\" tests=\"4+4\" time=\"4.867\" failures=\"0\" name=\"TestRateUs\">"
I tried also using to_i
on the backreferenced value, but I can't get the extracted value to add. Do I need to do something to the value to make it addable?