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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:22:31+00:00 2026-05-15T07:22:31+00:00

Alright, an easy one for you guys. We are using ActiveReport’s RichTextBox to display

  • 0

Alright, an easy one for you guys. We are using ActiveReport’s RichTextBox to display some random bits of HTML code.

The HTML tags supported by ActiveReport can be found here : http://www.datadynamics.com/Help/ARNET3/ar3conSupportedHtmlTagsInRichText.html

An example of what I want to do is replace any match of <div style="text-align:*</div> by <p style=\"text-align:*</p> in order to use a supported tag for text-alignment.

I have found the following regex expression to find the correct match in my html input:

<div style=\"text-align:(.*?)</div>

However, I can’t find a way to keep the previous text contained in the tags after my replacement. Any clue? Is it me or Regex are generally a PITA? 🙂

    private static readonly IDictionary<string, string> _replaceMap =
        new Dictionary<string, string>
            {
                {"<div style=\"text-align:(.*?)</div>", "<p style=\"text-align:(.*?)</p>"}
            };

    public static string FormatHtml(string html)
    {
        foreach(var pair in _replaceMap)
        {
            html = Regex.Replace(html, pair.Key, pair.Value);
        }

        return html;
    }

Thanks!

  • 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-15T07:22:32+00:00Added an answer on May 15, 2026 at 7:22 am

    Use $1:

    {"<div style=\"text-align:(.*?)</div>", "<p style=\"text-align:$1</p>"}
    

    Note that you could simplify this to:

    {"<div (style=\"text-align:(?:.*?))</div>", "<p $1</p>"}
    

    Also it is generally a better idea to use an HTML parser like HtmlAgilityPack than trying to parse HTML using regular expressions. Here’s how you could do it:

    HtmlDocument doc = new HtmlDocument();
    doc.LoadHtml(html);
    foreach (var e in doc.DocumentNode.Descendants("div"))
        e.Name = "p";
    doc.Save(Console.Out);
    

    Result:

    <p style="text-align:center">foo</p><p style="text-align:center">bar</p>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Alright, to start with let's look at some code: <html> <body> <script type=text/javascript> function
Alright, this is an easy one: What's the difference between Application.ThreadException and AppDomain.CurrentDomain.UnhandledException ?
Alright, I know how the fieldset / legend works out in HTML. Say you
Alright, I'm just trying to learn about using Contact information, but I'm a bit
Alright I'm a bit baffled by this one. Changing an unrelated int property on
Alright, so I got two angles. One is the joystick's angle, and the other
Alright. So I figure it's about time I get into unit testing, since everyone's
Alright, currently I have my SWF hitting a php file that will go and
Alright, I have been doing the following (variable names have been changed): FileInputStream fis
Alright. So I have a very large amount of binary data (let's say, 10GB)

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.