我有以下字符串:
{Name}({Age})
我想要得到以下内容:
()
我尝试过这段代码:
@"\{([^\}]+)\}" Only return {Name}
"({)(.*)(})" Return {Name}({Age}
但它们都没有达到我想要的效果。
如何做到这一点?
最佳答案
这应该可以做到:
class Program
{
static void Main(string[] args)
{
string input = @"{Name}({Age})";
string output = Regex.Replace(input, @"\{.*?\}", "");
Console.WriteLine(output); // "()"
}
}
关于c# - 如何替换整个文本中两个字符之间的字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60690545/