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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:41:30+00:00 2026-06-03T03:41:30+00:00

I want to do two replacement in a string, and i know how to

  • 0

I want to do two replacement in a string, and i know how to write the regex in php, curently i am not familiar with c++ boost.

// Replace all doubled-up <BR> tags with <P> tags, and remove fonts.
    $string = preg_replace("/<br\/?>[ \r\n\s]*<br\/?>/i", "</p><p>", $string);
    $string = preg_replace("/<\/?font[^>]*>/i", "", $string);

how to write the code in c++ boost?

Thanks in advance.

  • 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-03T03:41:31+00:00Added an answer on June 3, 2026 at 3:41 am

    All the usual warnings about parsing HTML with regexes apply.

    #include <boost/regex.hpp>
    #include <iostream>
    #include <string>
    
    int main()
    {
      boost::regex double_br("<br/?>[ \\r\\n\\s]*<br/?>", boost::regex::icase);
      boost::regex fonts("</?font[^>]*>", boost::regex::icase);
    
      std::string cases[] = {
        "foo<br><br>bar",
        "one<br/><br>two",
        "a<br>   <br/>b",
        "a<br><br>c<br/><br/>d",
        "<font attr=\"value\">w00t!</font>",
        "<font attr=\"value\">hello</font><font>bye</font>",
        ""
      };
    
      for (std::string *s = cases; *s != ""; ++s) {
        std::cout << *s << ":\n";
    
        std::string result;
        result = boost::regex_replace(*s, double_br, "</p><p>");
        result = boost::regex_replace(result, fonts, "");
    
        std::cout << "  - [" << result << "]\n";
      }
    
      return 0;
    }
    

    Output:

    foo<br><br>bar:
      - [foo</p><p>bar]
    one<br/><br>two:
      - [one</p><p>two]
    a<br>   <br/>b:
      - [a</p><p>b]
    a<br><br>c<br/><br/>d:
      - [a</p><p>c</p><p>d]
    <font attr="value">w00t!</font>:
      - [w00t!]
    <font attr="value">hello</font><font>bye</font>:
      - [hellobye]
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to make two regex replacements on one string, i.e. in Java terms
I want two special methods: one that runs for all URLs one that runs
I want two objects to share a single string object. How do I pass
I want sed to omit all non-matching lines, and only output the replaced string
I want to write code that compiles conditionally and according to the following two
Suppose we want two constructors for a class representing complex numbers: Complex (double re,
I want these two print functions to do the same thing: unsigned int Arraye[]
I want to merge two branches that have been separated for a while and
I want to take two lists and find the values that appear in both.
I want to create two widgets in flex. One for the movies ( that

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.