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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:42:24+00:00 2026-06-11T06:42:24+00:00

why does the following boost regex not return the results I am looking for

  • 0

why does the following boost regex not return the results I am looking for (starts with 0 ore more whitespace followed by one or more asterisk)?

boost::regex tmpCommentRegex("(^\\s*)\\*+");

for (std::vector<std::string>::iterator vect_it =
    tmpInputStringLines.begin(); vect_it != tmpInputStringLines.end();
    ++vect_it) {

    boost::match_results<std::string::const_iterator> tmpMatch;
    if (boost::regex_match((*vect_it), tmpMatch, tmpCommentRegex,
        boost::match_default) == 0) {

        std::cout << "Found comment " << (*vect_it) << std::endl;
    } else {
        std::cout << "No comment" << std::endl;
    }
}

On the following input:

* Script 7
[P]%OMO      * change
[P]%QMS      * change
[T]%OMO      * change
[T]%QMM      * change
[S]%G1       * Resume
[]

This should read

Found comment * Script 7
No comment
No comment 
No comment 
No comment 
No comment 
No comment 
  • 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-11T06:42:26+00:00Added an answer on June 11, 2026 at 6:42 am

    Quoting from the documentation for regex_match:

    Note that the result is true only if the expression matches the whole of the input sequence. If you want to search for an expression somewhere within the sequence then use regex_search. If you want to match a prefix of the character string then use regex_search with the flag match_continuous set.

    None of your input lines are matched by your regular expression as a whole, so the program works as expected. You should use regex_search to get the desired behavior.

    Besides, regex_match and regex_search both return bool and not int, so testing for == 0 is wrong.

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

Sidebar

Related Questions

The following does not compile: class Foo { public: Foo( boost::shared_ptr< Bar > arg
Why does the following code not allow foo(ptr) to be called ? #include <boost/scoped_ptr.hpp>
Does anyone have any idea why the following code would output no match? boost::regex
The following example from boost bind does not work for me: #include <boost/bind.hpp> struct
Can any one tell me? what does following means in ruby program: obj =
I'm getting crazy with this IE 7... ==> hhttp://neu.emergent-innovation.com/ Why does following function not
I have ran into yet another problem I do not understand. The following does
In the following code, gcc does not instantiate the NSP::Admin and NSP::Server objects. It
I'm going mad with the following problem which does not happen on any other
The following code using boost::asio will not compile: #ifndef _SERVER_H_ #define _SERVER_H_ #include Connection.h

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.