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

  • SEARCH
  • Home
  • 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 1046929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:13:25+00:00 2026-05-16T16:13:25+00:00

The input is a string representing a list of elements. A list is defined

  • 0

The input is a string representing a list of elements.

A list is defined as an open curly { followed by 0 or more elements separated by whitespace followed by a closed curly }.

An element is either a literal or a list of elements.

A literal is a succession of non-whitespace characters. If an element contains a curly bracket, it must be escaped with a backslash : \{ and \}. (Or you could assume curlies are not allowed inside literals, for simplicity)

Example:

"{abc { def ghi } 7 { 1 {2} {3 4} } {5 6} x\{yz \}foo }"

No curlies inside literals:

"{abc { def ghi } 7 { 1 {2} {3 4} } {5 6} xyz foo }"

(This is a simplified definition of a Tcl list.)

What I want to know is: can the input be split into the elements of the outermost loop using regex?

Expected output:

abc
{ def ghi }
7
{ 1 {2} {3 4} }
{5 6}
x{yz
}foo

The real question is: can this be done with a Regex?

I’m most interested in the .NET flavour, but will accept any answers.

I’ll post my own assumption in an answer, and see if it’s validated or destroyed.

  • 1 1 Answer
  • 1 View
  • 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. Editorial Team
    Editorial Team
    2026-05-16T16:13:26+00:00Added an answer on May 16, 2026 at 4:13 pm

    Well, the edit removes curly braces from tokens and takes the sting from the question, and now it is easily doable with .Net Regexes, using balancing groups. It is simply matching braces, which is a basic example.
    Much like KennyTM’s answer, this will only work if you remove the top level braces, or it will match the whole input.
    Again, this is better used for recreational purposes:

    (?:                    # try matching...
        (?:\\[{}]|[^\s{}])+\s*? # a literal (allow escaped curly braces)
        |                       # OR
        (?<Curly>{)\s*          # "{" and push to stack
        |                       # OR
        (?<-Curly>})\s*?        # "}", pop from stack and fail if the stack is empty
    )+?                    # ...a few times, and stop whenever you can.
    (?(Curly)(?!))         # Make sure there aren't any extra open curly braces
    

    For much more details see this article: Regex Balancing Group in Depth

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

Sidebar

Related Questions

I would like to convert a string input representing numbers to the respective numeric
My input data is a string representing the kind of datastore model I want
I'm reading a string representing a date, yet it seem to ignore the input
This is my use case: Input is a string representing an Oracle PL/SQL statement
A string 2012-03-02 representing March 2nd, 2012 is given to me as an input
Part of my .NET application needs to take an input string (representing a URI)
In the following input string: {$foo}foo bar \\{$blah1}oh{$blah2} even more{$blah3} but not{$blarg}{$why_not_me} I am
My input string is '16-MAR-2010 03:37:04' and i want to store it as datetime.
my input String is : 2010-03-24T17:28:50.000Z output pattern is like: DateFormat formatter1 = new
Sample input string: char *str = 12345.567675; And the desired output if I need

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.