It’s the replace function that substitutes the captured subgroup for the token $1. The Number constructor has no idea what to do with it. Do a RegExp.match instead of a String.replace to pull out the actual captured value, then you can parseInt it or whatever to get an integer to work with.
This looks suspiciously like an answer to a task I am trying to automate in Drafts: the cleanup of annotation text sent from iAnnotate PDF reader. Care to share more about your setup here? I don’t have a good enough RegEx expertise to accomplish what I want, and your page offset here looks like more than I could have hoped for.