Boost logo

Boost Users :

Subject: Re: [Boost-users] [Regex] subexpressions
From: John Maddock (john_at_[hidden])
Date: 2008-11-19 12:05:40


Carsten Witzel wrote:
>> Hi,
>>
>> I'm using the Regex library for the first time with Visual Studio
>> 2008. I've created a simple win32 console project, which works fine.
>>
>> The code is
>>
>> -------------------------------------
>> const char *pattern = "^(\\w*)\\s*=\\s*(\\w*).*";
>> const char *text = "Key = Value; Comment";
>>
>> boost::regex re(pattern);
>> boost::cmatch match;
>>
>> std::cout << pattern << std::endl;
>>
>> std::cout << text << std::endl;
>>
>> if (regex_match(text, match, re)) {
>> std::cout << "--> " << match.size() << std::endl;
>> for (int i = 0; i < match.size(); ++i) {
>> std::cout << i << ": " << match[i] << std::endl;
>> }
>> }
>> -------------------------------------
>>
>> And the output is as expected:
>>
>> --------------------------------------
>> ^(\w*)\s*=\s*(\w*).*
>> Key = Value; Comment
>> --> 3
>> 0: Key = Value; Comment
>> 1: Key
>> 2: Value
>> --------------------------------------
>>
>>
>> However, I've tried to use the same code with the C/C++-API of a
>> commercial software, and here I get the following output:
>> --------------------------------------
>> ^(\w*)\s*=\s*(\w*).*
>> Key = Value; Comment
>> --> 3
>> - 0: Key = Value; Comment
>> - 1: Key = Value; Comment
>> - 2: Value; Comment
>> --------------------------------------
>>
>> Does anybody have an idea what's wrong here? Unfortunately, I'm not
>> allowed to post any header files, so I need some hints where to look
>> for a solution by myself.

I'm not sure what you mean here: do you mean that code which works with
Boost.Regex fails with another/commercial implementation of the TR1 regex
library? If so you'll have to contact the vendor I'm afraid, or else use
Boost.Regex instead ;-)

HTH, John.


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