Используйте отрицательный взгляд позади (?<! )
и отрицательный взгляд вперед (?! )
, который остановит совпадение, если встретит '
, например
(?<!')\(|\)(?!')
В примере это объясняется как комментарий:
string pattern =
@"
(?<!')\( # Match an open paren that does not have a tick behind it
| # or
\)(?!') # Match a closed paren tha does not have tick after it
";
var text = "(name equal '('John')')";
// Ignore Pattern whitespace allows us to comment the pattern ONLY, does not affect processing.
var final = Regex.Replace(text, pattern, string.Empty, RegexOptions.IgnorePatternWhitespace);
Результат
имя равно '(' Джон ')'