Hamid Reza
Hamid Reza

Reputation: 2973

How to replace string between two characters in whole text?

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?

Upvotes: 2

Views: 246

Answers (1)

Daniel
Daniel

Reputation: 9829

This should do it:

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

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

        Console.WriteLine(output); // "()"
    }
}

Upvotes: 3

Related Questions