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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:10:05+00:00 2026-06-18T12:10:05+00:00

I can have 0 or many substrings within a text area in the format

  • 0

I can have 0 or many substrings within a text area in the format {key-value}Some text{/key},

For example This is my {link-123}test{/link} text area

I’d like to iterate through any items that match this pattern, perform and action based on the key and value, then replace this substring with a new string (a anchor link that is retreived by the action based on the key).

How would I achieve this in C#?

  • 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-06-18T12:10:06+00:00Added an answer on June 18, 2026 at 12:10 pm

    If these tags are not nested, then you only need to iterate once over the file; if nesting is possible, then you need to do one iteration for each level of nesting.

    This answer assumes that braces only occur as tag delimiters (and not, for example, inside comments):

    result = Regex.Replace(subject, 
        @"\{                # opening brace
        (?<key>\w+)         # Match the key (alnum), capture into the group 'key'
        -                   # dash
        (?<value>\w+)       # Match the value (alnum), capture it as above
        \}                  # closing brace
        (?<content>         # Match and capture into the group 'content':
         (?:                # Match...
          (?!\{/?\k<key>)   # (unless there's an opening or closing tag
          .                 # of the same name right here) any character
         )*                 # any number of times
        )                   # End of capturing group
        \{/\k<key>\}        # Match the closing tag.", 
        new MatchEvaluator(ComputeReplacement), RegexOptions.Singleline | RegexOptions.IgnorePatternWhitespace);
    
    public String ComputeReplacement(Match m) {
        // You can vary the replacement text for each match on-the-fly
        // m.Groups["key"].Value will contain the key
        // m.Groups["value"].Value will contain the value of the match
        // m.Groups["value"].Value will contain the content between the tags
        return ""; // change this to return the string you generated here
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a product, and a product can have many images. This is through
I have many checkboxes having text as substring from a long message. This I
I have some users that can have many posts , and each of those
I got some advice about constructors but now I have many. Can I simplify
Some sites have many scripts. For example orionhub . In such a case Chrome's
We can have many handlers: touches handler, UIControl handler (buttons, sliders), performSelector, CADisplayLink, NSTimer
Each book can have many authors. And each author can author many books. class
Summary A parent can have many children. How do you write a service such
I have a class that I can have many instances of. Inside it creates
I have models Product and Category . Category can have many products. ( Product

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.