Your question is kind of hard to understand, I don't think it's clearly explaining what you need to do and what is wrong. I'm not sure if the links clarify as they are broken.
I think I see what you mean, but I may be wrong.
If you have a string like
var test = "(674,)|(,674)"
Where 674 is the "id", and you are trying to replace "674," and ",674" with "" to get "()|()"
Then your code should work fine excepting you need the "g" (global) flag as well to replace ALL instances.
Example:
var test = "(674,)|(,674)";
var id = "674";
var expr = new RegExp('(' + id + ',)|(,' + id + ')', 'gi');
var b = test.replace(expr, '');
alert(test);
alert(b);
You're using the same regular expression twice, so why not just save it?
If you're wondering why it doesn't replace instances of JUST "674" in addition to "674," or ",675"...well that's because you didn't write a regular expression to replace it! Yours only covers it with the commas.
If that IS what you are trying to do, replace ",674" and "674," and just plain "674" with null then here is a regex that will match all of those:
var expr = new RegExp(',?' + id + ',?', 'gi');
? matches the preceding character 0 or 1 times.
If you need to match only instances that occure withing ()|() it's pretty easy to adjust the preceding regex for that, I'll leave it as an exercise for the reader.