This is counter-intuitive behaviour if you're used to $replace's semantics. The logic itself makes sense in general (replacing from left to right in the string, not order of arguments), but does not make sense in the context of $replace.

$replacex should behave like $replace with respect to order of arguments.