I don't think that is correct:
The issue is the replacement at the END of the string.
When you have GLOBAL turn on, it fails.
When GLOBAL is OFF, it works.
I know this because Chris @ccstone and I discussed and tested this privately.
It is unfortunately that the use case he presented at the top does not make that clear.
So, rather than belabout this any further, I will post a new topic with a new use case that clearly illustrates the issue.