使用消极的后视和消极的向前看,如果它遇到,这将停止匹配,例如(?<! )(?! )'(?<!')\(|\)(?!')该示例将其解释为注释: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);结果名称等于“(”约翰“)”