I reviewed the source code and it appears that this is how the token modifier has always behaved.
After conducting some more tests and doing a fair bit of research it appears that some of the functionality provided by this function is not correct. Our function should (or at-least I thought it did) provide results similar to that of
preg-replace() in PHP (however it doesn't)
The following example returns the wrong result, when the replacement is blank the pattern should be removed from the result.
Code:
/echo $replacerx("/this/is/my/path/", "/$", "")
Instead we get a result of
[CMD] /this/is/my/path/
(This is because on PCRE failure or error the original string is returned as the result)
The code wasn't handling an empty replacement very well and it resulted in a failure.
I have corrected this for the next release.
Taking a slightly modified example from the preg-replace PHP webpage the following code would replace brown with black but it doesn't.
Code:
/echo $replacerx("The quick brown fox jumped over the lazy dog.", "brown", "black")
[CMD] black
Instead we get a result of black, I'm not sure what's going on here and I will need to investigate this issue further.
If we modify the pattern and replacement to use back references then everything works as expected.
Code:
/echo $replacerx("The quick brown fox jumped over the lazy dog.", "(.*)brown(.*)", "\1black\2")
I will need to investigate this further to fully understand why it doesn't work, its possible that its a mistake in my code or a limitation in the 3rd party helper functions I'm using.