|
Boost Users : |
From: Jonathon Douglas (madhon_at_[hidden])
Date: 2007-03-12 10:10:30
"John Maddock" <john_at_[hidden]> wrote in message
news:00b701c7648e$1b5e3180$69d36b51_at_fuji...
> Jonathon Douglas wrote:
>> I am trying to convert the following C# code over to using
>> boost::regex
>>
>> MatchCollection col = new
>> Regex(@"\w+").Matches(@"slx://account/123456"); string table =
>> col[1].Value;
>> string id = col[2].Value;
>>
>> Table would equal "account" and id would equal "123456" in this.
>>
>> Ive tried using regex_match with this but it always finds no matches.
>>
>> Any sugestions ?
>
> C++ gobbles up \'s in starings, so it looks you want "\\w+" so that the
> regex engine gets to see \w+
>
> John.
Hi,
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;
}
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