• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1020
  • Last Modified:

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


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#?

1 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

John500Author Commented:

>> 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#?

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now