如何使用c#正则表达式替换圆形brancket中的子字符串

本文关键字:brancket 字符串 何使用 正则表达式 替换 | 更新日期: 2023-09-27 18:29:03

假设我有一个原始字符串,如下所示:

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

我应该用什么正则表达式使它起作用?

正则表达式模式总是让我感到困惑。

如何使用c#正则表达式替换圆形brancket中的子字符串

您搜索此正则表达式:

'(([^)]*)')

并替换为:

('$1')

RegEx演示

代码:您可以使用Regex。替换方法:

string repl = Regex.Replace(input, @"'(([^)]*)')", "$1");