This is a bit off a long shot but a while back there was a long discussion about problems with the use of variables in Search/Replace actions. I'm not going to repeat it here but I will link to the solution I came up with (a KM subroutine macro) which also provides a link to the discussion I'm referring to.
My thinking is that you may be running into a similar problem so you might benefit from looking at the discussion/solution to see if it might help you...