Using regular expressions to match all characters in a C# string that are between curly brackets

Posted on 2008-11-04
Last Modified: 2013-12-17

I'm looking for the C# syntax that uses regular expressions to find all characters between the curly brackets of a C# string

string MyString =  {........};

Parse MyString here

Also, in this particular instance, is there any advantage of using Regular Expressions over the string functions that come with C#?

Question by:John500
    LVL 5

    Accepted Solution

    Try this:
    RegExp reg = new RegExp("\{(.*?)\}");
    Match m = reg.Match(YourString);
    if (m.Groups.Count > 1) {
       Console.WriteLine("Match: " + m.Groups[1].Value);
    } else {
       Console.WriteLine("No match");

    Open in new window


    Author Comment


    >> RegExp reg = new RegExp("\{(.*?)\}");

    I get an error on that line under each curly bracket which says:

    "Unrecognized escape sequence"

    If I take both '\' out the error goes away.  Are these necessary in C#?


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
    The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now