Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


how to find strings between curly brackets (using C# Regex split)

Posted on 2009-02-24
Medium Priority
Last Modified: 2013-12-17
I want to find strings between curly brackets (using C# Regex split)

sample string:
This is a test string {First curly bracket} This is a test string {Second curly bracket}

output i need in string array:
{First curly bracket}
{Second curly bracket}

Any help would be very useful. Please give code sample.
Question by:balajime
  • 2
LVL 27

Accepted Solution

ddrudik earned 2000 total points
ID: 23724531

using System;
using System.Text.RegularExpressions;
namespace myapp
  class Class1
      static void Main(string[] args)
          String sourcestring = "source string to match with pattern";
          Regex re = new Regex(@"\{[^}]*\}");
          MatchCollection mc = re.Matches(sourcestring);
          int mIdx=0;
          foreach (Match m in mc)
            for (int gIdx = 0; gIdx < m.Groups.Count; gIdx++)
                Console.WriteLine("[{0}][{1}] = {2}", mIdx, re.GetGroupNames()[gIdx], m.Groups[gIdx].Value);

Open in new window


Author Closing Comment

ID: 31550711
Great. Got answer in a minute. Your guys are expert.
LVL 27

Expert Comment

ID: 23724648
Thanks for the question and the points.

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
We are witnesses that everyone is saying that our children shouldn't "play" with a technology because it is dangerous. This article is going to prove that they are wrong.
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…

564 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