Note that there are some explanatory texts on larger screens.

plurals
  1. POBoost regex not working as expected in my code
    primarykey
    data
    text
    <p>I just started using Boost::regex today and am quite a novice in Regular Expressions too. I have been using "The Regulator" and Expresso to test my regex and seem satisfied with what I see there, but transferring that regex to boost, does not seem to do what I want it to do. Any pointers to help me a solution would be most welcome. As a side question are there any tools that would help me test my regex against boost.regex?</p> <pre><code>using namespace boost; using namespace std; vector&lt;string&gt; tokenizer::to_vector_int(const string s) { regex re("\\d*"); vector&lt;string&gt; 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 &lt; matches.size() ; ++i ) { string match(matches[i].first, matches[i].second); vs.push_back(match); } } return vs; } void _uttokenizer::test_to_vector_int() { vector&lt;string&gt; __vi = tokenizer::to_vector_int("0&lt;br/&gt;1"); for( int i = 0 ; i &lt; __vi.size() ; ++i ) INFO(__vi[i]); CPPUNIT_ASSERT_EQUAL(2, (int)__vi.size());//always fails } </code></pre> <p>Update (Thanks to Dav for helping me clarify my question): I was hoping to get a vector with 2 strings in them => "0" and "1". I instead never get a successful regex_match() (regex_match() always returns false) so the vector is always empty.</p> <p>Thanks '1800 INFORMATION' for your suggestions. The <code>to_vector_int()</code> method now looks like this, but it goes into a never ending loop (I took the code you gave and modified it to make it compilable) and find "0","","","" and so on. It never find the "1".</p> <pre><code>vector&lt;string&gt; tokenizer::to_vector_int(const string s) { regex re("(\\d*)"); vector&lt;string&gt; vs; cmatch matches; char * loc = const_cast&lt;char *&gt;(s.c_str()); while( regex_search(loc, matches, re) ) { vs.push_back(string(matches[0].first, matches[0].second)); loc = const_cast&lt;char *&gt;(matches.suffix().str().c_str()); } return vs; } </code></pre> <p>In all honesty I don't think I have still understood the basics of searching for a pattern and getting the matches. Are there any tutorials with examples that explains this?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload