Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 56535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T17:32:59+00:00 2026-05-10T17:32:59+00:00

.NET balanced group regexes make my head explode. I’ve got this string i’m trying

  • 0

.NET balanced group regexes make my head explode. I’ve got this string i’m trying to match:

other stuff blah blah....                     {                         stuff stuff                         {key:                             stuff                             stuff                         }                     } more stuff..... 

Here’s my regex:

[^{}]*                      # anything that isn't { } \{                          # starting with { (?>                         # atomic group: throw away backtracks on exit     [^{}]+   |     \{(?:\w+:)?(?<DEPTH>)   # on matching { plus optional 'word:' push stack     |     \}(?<-DEPTH>)           # on matching } pop stack )* (?(DEPTH)(?!))              # if depth unbalanced, fail match \}                          # ending with } [^{}]*                      # anything that isn't { } 

So, I’m trying to match balancing curly braces, where some of the opening curly braces have an optional word followed by a colon. The above regex matches my example string, but if i remove a curly brace, (i.e. ‘unbalancing it):

    other stuff blah blah....                     {                         stuff stuff                         {key:                             stuff                             stuff                      } more stuff..... 

…it still matches!

Can anyone tell me how to fix my regex?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T17:32:59+00:00Added an answer on May 10, 2026 at 5:32 pm

    Have you checked what it is matching in the second case? Since you don’t have any anchors, I think the engine starts the match just after the first ‘{‘. From there, until the end, the string matches.

    Try surrounding the pattern with \A and \z.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 67k
  • Answers 67k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer This should work: <%# Container.DataItem %> May 11, 2026 at 11:46 am
  • added an answer You may be running into some problems with how MATLAB… May 11, 2026 at 11:46 am
  • added an answer The -N instructs gzip to remove the filename/timestamp information. Actually,… May 11, 2026 at 11:46 am

Related Questions

.NET balanced group regexes make my head explode. I've got this string i'm trying
I've got a load-balanced (not using Session state) ASP.Net 2.0 app on IIS5 running
I use ASP.NET and WCF services in a load balanced web server environment, using
I'm trying to balance a set of currency values using vb.net. The totals for
.NET Framework: 2.0 Preferred Language: C# I am new to TDD (Test Driven Development).
.NET, Java and other high level database API's in various language often provide techniques
.NET developers out there! Need your opinion here! I am now using Visual Assist
.Net Compact Framework Scenario: User is on a screen. Device can't finds a printer
.NET has a lot of complex data structures. Unfortunately, some of them are quite
.NET newbie here... I'd like to make a button in a Windows form that

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.