Search and Replace Action using variables

Have a look at this, it may help you Subroutine to Perform Search/Replace Using Variable Patterns