How to match words in a string that are wrapped in curly brackets using RegEx with C#

1 Answer

0 votes
using System;
using System.Text.RegularExpressions;

class Program
{
    static void Main()
    {
        string input = "This is a {string} with {multiple} {words} wrapped in curly brackets.";
        string pattern = @"\{([^}]*)\}";

        MatchCollection matches = Regex.Matches(input, pattern);

        foreach (Match match in matches) {
            Console.WriteLine(match.Groups[1].Value);
        }
    }
}



/*
run:

string
multiple
words

*/

 



answered Mar 18 by avibootz
...