in reply to Match last instance of pattern
Is there only one line in the file you are processing? If not you have something of a problem because the substitution is applied to each line in the file.