in reply to Search and replace query
then if you do the substitution, check first if that variable is set.
And to remember to reset that variable in an appropriate place