Boost regex not working properly in my code

I just started using Boost :: regex today and is pretty new to Regular Expressions too. I use Regulator and Express to test my regex and seem to be happy with what I see there, but porting this regex to enhance does not seem to do what I want. Any pointers that will help me with the solution will be most welcome. As a side question, are there any tools to help me test my regex on boost.regex?

using namespace boost;
using namespace std;

vector<string> tokenizer::to_vector_int(const string s)
{
    regex re("\\d*");
    vector<string> vs;
    cmatch matches;
    if( regex_match(s.c_str(), matches, re) ) {
        MessageBox(NULL, L"Hmmm", L"", MB_OK); // it never gets here
        for( unsigned int i = 1 ; i < matches.size() ; ++i ) {
            string match(matches[i].first, matches[i].second);
            vs.push_back(match);
        }
    }
    return vs;
}

void _uttokenizer::test_to_vector_int() 
{
    vector<string> __vi = tokenizer::to_vector_int("0<br/>1");
    for( int i = 0 ; i < __vi.size() ; ++i ) INFO(__vi[i]);
    CPPUNIT_ASSERT_EQUAL(2, (int)__vi.size());//always fails
}

( , ): = > "0" "1". regex_match() (regex_match() false), .

"1800 INFORMATION" . to_vector_int() , ( , , , ) "0", "," "," " , "1".

vector<string> tokenizer::to_vector_int(const string s)
{
    regex re("(\\d*)");
    vector<string> vs;

    cmatch matches;

    char * loc = const_cast<char *>(s.c_str());
    while( regex_search(loc, matches, re) ) {
        vs.push_back(string(matches[0].first, matches[0].second));
        loc = const_cast<char *>(matches.suffix().str().c_str());
    }

    return vs;
}

, , . , ?

+3
1

, regex_match, regex_search:

regex_search regex_match match_results , ; , regex_match , regex_search .

. , regex_search, .

, , . :

regex re("(\\d*)");

, , regex_search:

char *where = s.c_str();
while (regex_search(s.c_str(), matches, re))
{
  where = m.suffix().first;
}

, .

, :

regex re("(\\d+).*?(\\d+)");

.

, \d * - "", . \d +, 1 .

+9

Source: https://habr.com/ru/post/1715031/


All Articles