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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:14:42+00:00 2026-06-13T14:14:42+00:00

Edit8: I’ve posted the solution first for anyone who might come along after me

  • 0

Edit8: I’ve posted the solution first for anyone who might come along after me with the same problem.

Solution:

Assigned regex with = instead of invoking the () operator. Worked fine. That was stupid.

#include <iostream>
#include <string>
#include <boost/xpressive/xpressive_dynamic.hpp>

int main()
{
    std::string str = "foobarfoo";
    boost::xpressive::sregex rex;
    std::string rstr = "foo";
    rex = boost::xpressive::sregex::compile(rstr, boost::xpressive::regex_constants::ECMAScript);
    if (boost::xpressive::regex_search(str, rex, boost::xpressive::regex_constants::match_continuous))
        std::cout << "Match found.";
    else
        std::cout << "No match found.";
    return 0;
}

Original Problem:

I’ve been fighting with xpressive for a while now, and I’ve yet to make anything work. With the following code:

#include <iostream>
#include <string>
#include <boost/xpressive/xpressive_dynamic.hpp>

int main()
{
    std::string str = "foobar";
    boost::xpressive::sregex rex;
    std::string rstr = "foo";
    rex(boost::xpressive::sregex::compile(rstr));
    if (boost::xpressive::regex_match(str, rex))
        std::cout << "Match found.";
    else
        std::cout << "No match found.";
    return 0;
}

I’m not finding the match I expect. Help would be greatly appreciated.

Edit: Tried changing the regex compile line to

rex(boost::xpressive::sregex::compile(rstr, boost::xpressive::regex_constants::ECMAScript));

Still nothing.

Edit2: Compiling with MinGW GCC 4.7

Edit3: I also tried changing the line where the regex string is declared to both

std::string rstr = ".*";

and

std::string rstr = "(.*)";

Still nothing.

Edit4: I’ve not got the following, still with no results:

#include <iostream>
#include <string>
#include <boost/xpressive/xpressive_dynamic.hpp>

    int main()
    {
        std::string str = "foobarfoo";
        boost::xpressive::sregex rex;
        std::string rstr = "(foo)";
        rex(boost::xpressive::sregex::compile(rstr));//;, boost::xpressive::regex_constants::ECMAScript));
        if (boost::xpressive::regex_search(str, rex, boost::xpressive::regex_constants::match_default))
            std::cout << "Match found.";
        else
            std::cout << "No match found.";
        return 0;
    }

Edit5: I’m expecting two matches at this point, the “foo” at both the beginning and end of str.

Edit6: Tried running regex_search with the match_continuous flag set hoping I could at least get it to pick up the prefix. No dice. Also tried compiling with ECMAScript flag and running regex_search with both match_default and match_continuous flags.

Edit7: I know strstr() will work here. That’s because this is a simple sample case. Boost is imperative in the actual application.

  • 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-13T14:14:43+00:00Added an answer on June 13, 2026 at 2:14 pm
    #include <iostream>
    #include <string>
    #include <boost/xpressive/xpressive_dynamic.hpp>
    
    int main()
    {
        std::string str = "foobar";
        std::string rstr = "foo";
        boost::xpressive::sregex rex = boost::xpressive::sregex::compile(rstr);
        if (boost::xpressive::regex_search(str, rex))
            std::cout << "Match found." << std::endl;
        else
            std::cout << "No match found." << std::endl;
    }
    

    Prints "Match found." for me. If you want to find all the matches …

    #include <iostream>
    #include <string>
    #include <boost/xpressive/xpressive_dynamic.hpp>
    
    int main()
    {
        std::string str = "foobarfoo";
        std::string rstr = "foo";
        boost::xpressive::sregex rex = boost::xpressive::sregex::compile(rstr);
        boost::xpressive::sregex_iterator it(str.begin(), str.end(), rex), end;
    
        for (; it != end; ++it )
            std::cout << "Match found at offset "
                      << ((*it)[0].first - str.begin())
                      << std::endl;
    }
    

    For me, this prints:

    Match found at offset 0
    Match found at offset 6
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Edit: The initial question was wrong, so some of the content might be a
EDIT After staring at this for 2 days, I do see one issue. I
EDIT: Problem solved... and unrelated to the phrasing of the question... sorry for the
Edit: The question in one line: How to pass along context from a MenuItem
Edit: I think I figured out the solution, but I'm still interested to know
Edit: I'm looking for solution for this question now also with other programming languages.
EDIT: Changed as I have a different issue with the same code 2nd Edit:
Edit: an important piece might be that I'm calling a cfc method via ajax...
EDIT I had a problem a while ago writing a program in C which
I've encountered a problem while writing code in Delphi. Namely I can't get acces

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.