假设我有一个这样的原始字符串:
Whatever here is (this is what i want to be replaced) Whatever here is
我想替换
this is what i want to be replaced
带
'this is what i want to be replaced'
我希望结果是:
Whatever here is ('this is what i want to be replaced') Whatever here is
我应该使用正则表达式来使其工作?
正则表达式模式总是让我感到困惑。
答案 0 :(得分:2)
您搜索此正则表达式:
\(([^)]*)\)
并替换为:
('$1')
代码:您可以使用Regex.Replace方法:
string repl = Regex.Replace(input, @"\(([^)]*)\)", "$1");