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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:01:25+00:00 2026-05-29T10:01:25+00:00

I admit it’s been a while since I’ve worked with C++, but from what

  • 0

I admit it’s been a while since I’ve worked with C++, but from what I can tell, my code should work. I’m trying to replace/remove all block comments from a file containing code. I put the whole file I’m searching into a string, and the string contains newline characters.

Here’s my code

std::tr1::regex rx1("[/][*][\S\s]*?[*][/]");
stringName = std::regex_replace(stringName, rx1, std::string(""));

As far as I can tell, this should match /*anything in here including new lines */

I’ve even tested it on http://gskinner.com/RegExr/, where it matches block comments perfectly. Problem is, block comments aren’t being replaced. Is this some kind of TR1 specific bug?

  • 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-29T10:01:26+00:00Added an answer on May 29, 2026 at 10:01 am

    Lightness Races in Orbit pushed me along the right path, but turns out the * and ? cannot be used on arguments within [] brackets. The way to do that is use a noncapturing group which has or statements.

    Code to find multi-line block comments:

    std::tr1::regex rx3("[/][*](?:\s|.|\n)*?[*][/]");
    

    (?:expression) is how to make a noncapturing group. You can apply the * and ? to the outside of that. Inside of it, use | as an or statement.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I must admit it's been a few years since my RegEx class and since
I'm afraid to admit, I haven't used C++ for a while now but i'm
I hate to admit it but I'm stuck trying to figure out how to
Background I admit, this question stems from an ultimate lack of deep understanding of
I'll admit the title is a bit confusing but it was hard to come
I admit I am being lazy here but is anyone aware of a free
I admit it is not the best title, but I don't know how to
So I'll admit that this is a homework assignment, but I'm not asking you
I must admit that I am new to jQuery and JS but I really
I admit I haven't grokked F# yet. But in the 30,000 foot descriptions, they

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.