Basically, my goal is to delete everything inside (), with the exception of lines inside "".
I followed the code here: Remove text between delimiters in a string (using regex?)
And it works great; but I have an additional requirement not to delete () s if they are in "". This is something that can be done with regex. I feel that I am dangerously close to the need for a different approach, like a true parser.
This is what I used ....
string RemoveBetween(string s, char begin, char end)
{
Regex regex = new Regex(string.Format("\\{0}.*?\\{1}", begin, end));
return regex.Replace(s, string.Empty);
}
source
share