Possible Duplicate:
Find a pattern to match ‘a’, ignoring that ‘a’ which lies within ‘b’ and ‘c’
If I have the following string (for instance)
string q = "select field1 from t1 where field1 in (select field1 from t2)";
In this case I have
a = " from"; b = @"\(.* from.*\)"; => " from" within parenthesis
You can see 'a' is a sub-string of 'b' here
The closest pattern I have is
string pat = @"^((?!\(.* from.*\)).)* from((?!\(.* from.*\)).)*$";
But I need 'pat' be modified a 'a' such that 'a' is not a sub-string of 'b'
... ('a' and 'b' are variable patterns). I am stuck at translating this in regular expression. I want to use
string answer=Regex.Relace(q , pat , ",field2 from");
Desired output: (value in answer should be)
"select field1,field2 from t1 where field1 in (select field1 from t2)"