I recently had the need to match content outside quotes, but avoid content inside quotes. For example, I have content like so:
this is content to replace, "but don't replace this string, it's \"important\"", but feel free to replace this.
The answer came from http://thisworkinglife.blogspot.com/2006/04/net-regular-expressions-finding.html supported by http://regexadvice.com/forums/thread/36369.aspx and http://www.regular-expressions.info/lookaround.html and http://aspnet.4guysfromrolla.com/articles/022603-1.aspx
The expression is added to the beginning of any other expression. Here it is:
(?<=^(([^\"]*(?<!\\\\)\"[^\"]*(?<!\\\\)\"[^\"]*)*|[^\"]*))
It means: "... and before it is an even number of double-quotes not preceeded by a \ or no quotes at all before it ..."
If you've never used look-ahead or look-behind expressions, they're incredibly cool. I understand...