Hi @Scott B:
This is really more of a StackOverflow question than a WordPress Answers question. I’ll take a stab at it but if this is not what you need I’d suggest deleting your question here and putting it up at SO.
The Replace()
function in Javascript can take a function as an argument. Ben Nadel (who is a bonafide jQuery/Javascript rockstar, at least in my book) has a great article covering how to use Replace()
with a callback (look for the subhead “Javascript String Replace() – Function Replace”):