I am working on a ASP.NET response filter that rewrites URL's to point to a different domain in specific situations.
Because ASP.NET chunks the response writes, my filter gets called several times before the page is fully streamed. This means that I need to be careful that each call to Regex.Replace doesn't double replace a url (You end up with http://foo.comhttp://foo.com/path).
To do this, I'm trying to use a negative lookbehind expression for the replace, but it doesn't seem to be working:
content = Regex.Replace(content,"((?<!" + newDomain + ")" + match + ")", newDomain + match);
This creates a regex like:
((?<!http://www.foo.com/)actual/url)
However, it seems to not respect the look behind and I am getting everything double replaced.
Any ideas?
EDIT: This regex works great when I use a tool like Regex Coach to test it against sample data.
EDIT 2: Added the slash, it is actually there.