2

I have the following string:

{Name}({Age})

I want to get the following:

()

I have tried this code:

@"\{([^\}]+)\}" Only return {Name}

"({)(.*)(})" Return {Name}({Age}

But none of them worked as I wanted.

How to do this?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Hamid Reza
  • 2,913
  • 9
  • 49
  • 76
  • 1
    Can you share the code which you have written to solve this problem? And also explain how that is not working for you? – Chetan Mar 15 '20 at 07:14
  • Does this answer your question? [How to replace the text between two characters in c#](https://stackoverflow.com/questions/20701818/how-to-replace-the-text-between-two-characters-in-c-sharp) – Hoshani Mar 15 '20 at 07:37

1 Answers1

3

This should do it:

class Program
{
    static void Main(string[] args)
    {
        string input = @"{Name}({Age})";

        string output = Regex.Replace(input, @"\{.*?\}", "");

        Console.WriteLine(output); // "()"
    }
}
Daniel
  • 9,491
  • 12
  • 50
  • 66