Boost logo

Boost Users :

Subject: Re: [Boost-users] [C++] Boost::Regex beginner question
From: P.C. (cavalo451_at_[hidden])
Date: 2008-12-19 10:44:28


thank you for the response. unfortunately, we've tried to use the
regex_replace function, but it gave an unexpected error:
'regex_replace' : undeclared identifier
we used it in the following way:

#include <windows.h>
#include <direct.h>
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <string>
#include <boost/regex.hpp>

using namespace std;
using namespace boost;

int main(int argc, char* argv[])
{
        boost::regex e("\<\<(\.\*?)\>\>");
        string str = "cavalo \<\<velaalev\>\> olavac";
        cout << regex_replace(str, e, "cavalo $1 olavac");
        return 0;
}

NOTE: the Regex++ we are using was downloaded from the original
author's site, not entirely with the Boost library. we can't
understand this error. if we downloaded and installed it according to
the installation instructions for VC++, how can a function be missing?

2008/12/18 Alan M. Carroll <amc_at_[hidden]>:
> Let's say you had an input form that was similar to that of Boost.Format
> except that you could specify type information by appending a '|' followed
> by the type, e.g. "%1|int%", and you could name the inserts as well as use
> numbers (e.g., "%count|int%"). After some preprocessing to pull out the
> types, you then wanted to strip the type specifiers to make the string
> Boost.Format compliant. So '%1|int%" would become "%1%" and "%2%" would
> remain unchanged (because type specifiers are not required).
>
> // This matches the insert strings, e.g. "%1|int%" with subexpressions for
> the number or name
> boost::regex const RXP_INSERT(
> "%(?:(\\d+)|([_a-z][_a-z0-9]*))(?:[|]([_a-z][_:a-z0-9]*))?%" ,
> boost::regex_constants::icase);
> // ...
> // Time to strip the type specifiers. We match each insert then replace with
> the first two groups,
> // exactly one of which will be set ($1 if a number, $2 if name)
> msgText = boost::regex_replace(msgText, RXP_INSERT, "%$1$2%");
> // No more type specifiers. Changing names to numbers is a bit more complex
> but this should illustrate
> // the principle.
>
> At 04:41 PM 12/18/2008, P.C. wrote:
>
> my doubt is the following: I want to know how to do search and replace
> regexp operations, like it can be done in Perl by using groups (expressions
> surrounded by parentheses), which allow to select the substrings, matched by
> the regexp, in the form of $1, $2
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>


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