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 7672229
In Process

The Archive Base Latest Questions

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

i know there are several questions about regex recursion in .net. I can write

  • 0

i know there are several questions about regex recursion in .net. I can write somewhat complex regex expressions but this recursion is beyond me, i am just not able to write it.

This are the questions closest to what i want.

first question, second question.

but it matches the entire string, i want the matches in a collection preferably the innermost match first or in some order. Also it matches on one opening character and one closing character. Mine is 2 chars for opening and closing, [! and !]

my input string will be something like this.

[!a='test' b='[!a='innertest' b='innervalue'!]'!]

I need to find the innertest section, [!a='innertest' b='innervalue'!], first and then evaluate it through one of my expression trees. then evaluate the parent one containing it.

Can anyone help with this?

  • 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. Editorial Team
    Editorial Team
    2026-05-31T16:14:17+00:00Added an answer on May 31, 2026 at 4:14 pm

    Here’s a pattern that might satisfy your needs:

    ^\[!((?<n>\w+='\[!)|(?<inner-n>!]')|\w+='(?!\[!)[^']*'| )*!](?!(n))$
    

    It will give the innermost item for each item in order. To explain what I mean, given the code:

    [!a='test' c='[!x='blah'!]' b='[!a='[!y='innermost'!]' b='innervalue'!]' !]
    

    It will give the following matches (in the capture collection for the group “inner”):

    x='blag'
    y='innermost'
    a='[!y='innermost'!]' b='innervalue'
    

    So, for each x=y item in the [! .. !], it will give the matches in order from innermost outwards.

    If you also want the overall expression to be captured you can modify it like this:

    ^(?<n>\[!)((?<n>\w+='\[!)|(?<inner-n>!]')|\w+='(?!\[!)[^']*'| )*(?<inner-n>!])(?!(n))$
    

    Giving:

    x='blag'
    y='innermost'
    a='[!y='innermost'!]' b='innervalue'
    a='test' c='[!x='blag'!]' b='[!a='[!y='innermost'!]' b='innervalue'!]' 
    

    And to explain the regex:

    ^       # start of string
    \[!     # start of overall [! .. !]
    (       # either ...
        (?<n>\w+='\[!)|     # a complex x='[! .. !]' containing a nested [! .. !] - push this onto the stack 'n'
        (?<inner-n>!]')|    # end of a nested [! .. !] - pop stack 'n', and capture the contents into 'inner'
        \w+='(?!\[!)[^']*'| # a simple x='asdf' with no nested [! .. !]
         )                  # or a space
    *       # as many times as you want
    !]      # the end of the overall [! .. !]
    (?!(n)) # assert that the 'n' stack is empty, no mismatched [! .. !]
    $       # end of string
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know there are several questions similar, but I can't find one that answers
I know there are already several similar questions here, but I need some recommendations
I've seen several questions on SO about this, but none of them quite fit
I know that there are already several questions on StackOverflow about std::string versus std::wstring
I know there are several similar questions out there such as this one. I
I know there are similar questions out there, but I'm having trouble with this
I know there are several ways to deploy a .net windows client application: There's
I know there are several libraries to connect to XMPP servers, but is there
I know there are several threads and posts regarding this issue in the internet
I know there have been a few threads on this before, but I have

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.