Boost logo

Boost Users :

From: Jonathon Douglas (madhon_at_[hidden])
Date: 2007-03-12 14:32:28


>>
>>Ive tried that, however been a complete newbie to boost im probably
> still
>>missing something obvious. Heres the test code so far
>>
>>#include <stdlib.h>
>>#include <iostream>
>>#include <string>
>>#include <boost/regex.hpp>
>>using namespace std;
>>int main (int argc, char *argv[])
>>{
>>string uri ("slx://account/12345");
>>boost::regex re ("\\w+");
>>boost::cmatch what;
>>if (boost::regex_match(uri.c_str(), what, re))
>>{
>>cout << what[0] << endl;
>>cout << what[1] << endl;
>>cout << what[2] << endl;
>>}
>>else
>>{
>>cout << "nowt matched" << endl;
>>}
>>return 0;
>>}
>
> It looks like there is some confusion about boost::regex_match does. It
> attempts to match the entire string against the regular expression
> (imagine an implicit ^ and $ around the expression).
>
> I am not familiar with the C# library, but it looks like "Matches" finds
> all of the matches in the string and returns an array of them. Is this
> correct?

Yes thats correct.

> If it is, then there are two things you can do:
>
> Option 1: Change your expression to use captures. It might look like
> "slx://(\\w+)/(\\w+)". If you drop this ion your code above, you should
> see that what[0] is the entire uri, what[1] is "account" and what[2] is
> "12345". I generally prefer this method, as it also provides syntax
> checking.
>
>

This option worked perfectly.

Thanks for the help Andrew.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net