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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:37:05+00:00 2026-05-13T19:37:05+00:00

How do I solve the problem below? I’m creating a simple content management system,

  • 0

How do I solve the problem below?

I’m creating a simple content management system, where there is a HTML template with specific markup that denotes where content should be:

<html><head></head><body><!-- #Editable "Body1" --><p>etc etc</p><!-- #Editable "Extra" --></body></html>

Separate from this, there is content in a database field that looks a little like this:

<!-- #BeginEditable "Body1" -->This is Test Text<!-- #EndEditable --><!-- #BeginEditable "Extra" -->This is more test text<!-- #EndEditable -->

As you can guess I need to merge the two, that is, replacing

<!-- #Editable "Body1" -->

with:

This is Test Text

I’ve begun the code here. But I’m having problems using the Regex Replace function that should be located at the very bottom of that For/Each….

    //Html Template
    string html = "<html><head></head><body><!-- #Editable \"Body1\" --><p>etc etc</p><!-- #Editable \"Extra\" --></body></html>";        

    //Regions that need to be put in the Html Template
    string regions = "<!-- #BeginEditable \"Body1\" -->This is Test Text<!-- #EndEditable --><!-- #BeginEditable \"Extra\" -->This is more test text<!-- #EndEditable -->";

    //Create a Regex to only extract what's between the 'Body' tag
    Regex oRegex = new Regex("<body.*?>(.*?)</body>", RegexOptions.Multiline);

    //Get only the 'Body' of the html template
    string body = oRegex.Match(html).Groups[1].Value.ToString();

    // Regex to find sections inside the 'Body' that need replacing with what's in the string 'regions'
    Regex oRegex1 = new Regex("<!-- #Editable \"(.*?)\"[^>]*>",RegexOptions.Multiline);
    MatchCollection matches = oRegex1.Matches(body);

    // Locate section titles i.e. Body1, Extra
    foreach (Match match in matches)
    {
        string title = oRegex1.Match(match.ToString()).Groups[1].ToString();
        Regex oRegex2 = new Regex("<!-- #BeginEditable \"" + title + "\"[^>]*>(.*?)<!-- #EndEditable [^>]*>", RegexOptions.Multiline);
        //
        //
        // Replace the 'Body' sections with whats in the 'regions' string cross referencing the titles i.e. Body1, Extra
        //
        //
        //
    }
  • 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-13T19:37:05+00:00Added an answer on May 13, 2026 at 7:37 pm

    Not optimized for performance (or anything else) but it’s simple and works :

    var html = "<html><head></head><body><!-- #Editable \"Body1\" --><p>etc etc</p><!-- #Editable \"Extra\" --></body></html>";
    var regions = "<!-- #BeginEditable \"Body1\" -->This is Test Text<!-- #EndEditable --><!-- #BeginEditable \"Extra\" -->This is more test text<!-- #EndEditable -->";
    var regionRegex = new Regex(@"<!-- #BeginEditable ""(?<Name>\w+)"" -->(?<Content>.*?)<!-- #EndEditable -->", RegexOptions.Multiline);
    var regionMatches = regionRegex.Matches(regions);
    
    foreach (Match regionMatch in regionMatches)
    {
        var regionName = regionMatch.Groups["Name"].Value;
        var regionContent = regionMatch.Groups["Content"].Value;
        html = html.Replace(string.Format(@"<!-- #Editable ""{0}"" -->", regionName), regionContent);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I found two ways to resolve this issue. One is… May 15, 2026 at 12:30 am
  • Editorial Team
    Editorial Team added an answer Add to crontab -e this: 0 0 1 * *… May 15, 2026 at 12:30 am
  • Editorial Team
    Editorial Team added an answer Here's the XSD: <?xml version="1.0" encoding="utf-8"?> <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">… May 15, 2026 at 12:30 am

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.