Search code examples
c#regexstringc#-4.0split

Get values between curly braces c#


I never used regex before. I was abel to see similar questions in forum but not exactly what im looking for

I have a string like following. need to get the values between curly braces

Ex: "{name}{[email protected]}"

And i Need to get the following splitted strings.

name and [email protected]

I tried the following and it gives me back the same string.

string s = "{name}{[email protected]}";
string pattern = "({})";
string[] result = Regex.Split(s, pattern);

Solution

  • Is using regex a must? In this particular example I would write:

    s.Split(new char[] { '{', '}' }, StringSplitOptions.RemoveEmptyEntries)