Boost logo

Boost :

From: Daniel Frey (daniel.frey_at_[hidden])
Date: 2002-03-19 11:59:14


Hello,

given the following program:

#include <iostream>
#include <string>
using namespace std;

#include <boost/regex.hpp>

int main()
{
   const std::string in = "vector< X, allocator< X > >";

   const std::string search =
"(vector|deque|list)\\s*<\\s*(.*?)\\s*,\\s*allocator\\s*<\\s*\\2\\s*>\\s*>";
   const std::string replace = "$1<$2>";

   const std::string out = boost::regex_merge( in, boost::regex( search
), replace );

   cout << "in: `" << in << "'\n"
        << "search: `" << search << "'\n"
        << "replace: `" << replace << "'\n"
        << "out: `" << out << "'\n"
        << "excepted: `vector<X>'" << endl;
}

I receive the following output:

in: `vector< X, allocator< X > >'
search:
`(vector|deque|list)\s*<\s*(.*?)\s*,\s*allocator\s*<\s*\2\s*>\s*>'
replace: `$1<$2>'
out: `vector< X>'
excepted: `vector<X>'

Note the extra space in 'out'. Is this a bug or feature I haven't
understood? (I'm using boost 1.25.1, but the changelog doesn't state any
update for regex since then...)

Regards, Daniel

--
Daniel Frey
aixigo AG - financial training, research and technology
Schloß-Rahe-Straße 15, 52072 Aachen, Germany
fon: +49 (0)241 936737-42, fax: +49 (0)241 936737-99
eMail: daniel.frey_at_[hidden], web: http://www.aixigo.de

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk